Skip to content

Latest commit

 

History

History
 
 

10 while Loop

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

10. while Loop

while

A while loop continues running while a condition is true, and stops when the condition becomes false.

int i = 0;
while (i < 5) {
  cout << i << "\n";
  i++;
}

do-while

A variation of the while loop is the do-while loop. The difference here is that the condition to check that the loop should continue is evaluated at the end of code block instead of at the beginning of the code block.

int i = 0;
do {
  cout << i << "\n";
  i++;
}
while (i < 5);