- Learn C# in 7 days
- Gaurav Aroraa
- 109字
- 2021-07-08 09:51:29
The do...while loop
This helps us execute a statement or a statement of block repeatedly until it evaluates the expression to false. In do...while statement, a block of statement executes first and then it checks the condition under while, which means a statement or block of statements that execute at least once.
Take a look at the following code:
private static void DoWhileStatementExample() { WriteLine("do...while example"); Write("Enter repeatitive length:"); int length = Convert.ToInt32(ReadLine()); int count = 0; do { count++; WriteLine(newstring('*',count)); } while (count < length); }
In the preceding code snippet, the statement of the do block executes until the statement of the while block evaluates to false.