Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0081 do...while loop

do..while loop checks the loop control bool expresion after executing the loop body. Therefore the loop body gets executed at least once. The do..while has the following form. do{ loop body; }while(bool expression) We can change the while loop to do while loop. using System; class Program { static void Main(string[] args) { int i = 5; do { Console.WriteLine(i); i--; } while (i > 0); } } The output: 5 4 3 2 1