Sun 22 July 2018, in category Loop
A do-while loop is a similar construct to the while loop as it allows you to iterate over a set of statements while the given expression is true. Note however, that a do-while loop will check the condition after executing the code inside the loop. In our examples below, the do-while loop increments the i value as long as its less than 10.
do
{
System.out.println(i);
i++;
} while(i < 10);
do
{
Console.WriteLine(i);
i++;
} while(i < 10);
# Note: Python doesn't support do while, but can be emulated as shown below.
while True:
print(i)
i=i+1
if i >= 10:
break
do {
console.log(i);
i++;
} while ( i < 10);
for {
fmt.Println(i)
i++
if i >= 10 {
break
}
}