做 - 循环

它类似于 while 循环,除了它测试循环体末端的条件。无论条件是否为真,Do-While 循环都会执行一次循环。

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