Do-while is a loop that executes one or more times
Output:
The condition is false but num
is printed.
The loop body executes before the condition is checked.
Basically for conditions that are always false, the loop executes once unlike the while cycles which won't execute.
Output:
The loop executes 10 times (for num
from 0 to 9).
The cycle ends when num
reaches value of 10.
Infinite Loop has a condition that's always true.
It can be created due to development mistake or used in advanced algorithm.
Here are examples:
Output:
Since num
is 0 and never gets modified, the loop repeats infinitely.
while(true)
is a way to specify endless loop.