Do - While Loop C# with Example



Do - While Loop C# with Example

It is similar to a while loop, except that it tests the condition at the end of the loop body. The Do - While loop 
executes the loop once irrespective of whether the condition is true or not. 
int[] numbers = new int[] { 6, 7, 8, 10 }; 
// Sum values from the array until we get a total that's greater than 10, 
// or until we run out of values. 
int sum = 0; 
int i = 0; 
do 
{ 
sum += numbers[i]; 
i++; 
} while (sum <= 10 && i < numbers.Length); 
System.Console.WriteLine(sum); // 13 

0 Comment's

Comment Form

Submit Comment