+ 2
How to build do while?
3 Antworten
+ 10
We use the do-while loop to check its condition at the end of the loop. A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
Some example
class Program
{
static void Main(string[] args)
{
int a = 5;
do
{
Console.WriteLine("value of a: {0}", a);
a = a + 1;
}
while (a < 10);
}
}
Result:
value of a: 5
value of a: 6
value of a: 7
value of a: 8
value of a: 9
+ 4
int i=0;
int sum=0;
do{
sum+=i;
i++;
}
while(i<10)
+ 1
Is the first answer to this question written in Java?