---
title: "define while loop."  
description: "define while loop."  
author: "Anonymous User"  
published: 2020-01-21  
updated: 2020-01-21  
canonical: https://www.mindstick.com/forum/155714/define-while-loop  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# define while loop.

Please [briefly explain](https://www.mindstick.com/forum/156854/briefly-explain-the-concept-of-constructor-overloading) me about [while loop](https://www.mindstick.com/forum/34579/while-loop-in-python) with some [coding](https://www.mindstick.com/articles/12290/teaching-coding-from-the-metal-up-or-from-the-glass-back) as a example and with its [flow](https://answers.mindstick.com/qa/105072/how-to-trade-with-the-money-flow-index) chart.

## Replies

### Reply by Nishi Tiwari

While loop will execute the block of statement until the specified condition evaluates true.

**[For loop is used in case,](https://www.mindstick.com/forum/155713/what-is-for-loop-statement)** when we know how many times the block of statement will execute but in case if we don’t know the exact number of times the body will execute then while loop is best suited in that case.

Using keyword, while we create the body of while loop.

## Syntax

```
while(condition)
{
    //statement of body
}
```

Here, if condition evaluates true then only the block of statement will execute and condition will be checked again to execute the statement with in the while loop.

If condition evaluates false then while loop stops the execution of statement and programs comes out of loop.

## Example

```
using System;
 namespace whileLoop
 {  class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            while (i <= 4)
            {
                Console.WriteLine("i value: {0}", i);
                i++;
            }
            Console.WriteLine("Press Enter Key to Exit..");
            Console.ReadLine();
        }
    }
}
```

![define while loop.](https://www.mindstick.com/mindstickforums/af3cd0fd-ad2f-423e-a91a-217429a7c75a/images/1b7d9bcf-0573-4c74-8f12-b72659302c6e.png)

![define while loop.](https://www.mindstick.com/mindstickforums/af3cd0fd-ad2f-423e-a91a-217429a7c75a/images/bd033c9a-a932-48f6-9e3c-ee371cf18470.jpeg)


---

Original Source: https://www.mindstick.com/forum/155714/define-while-loop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
