做 - 迴圈

它類似於 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