< Previous | Contents | Next >
Like while loops, do loops let you repeat a section of code based on an expression. The difference is that a do loop tests its expression after each loop iteration. This means that the loop body is always executed at least once. Here’s a generic form of a do loop:
do
statement; while (expression);
The program executes statement and then, as long as expression tests true, the loop repeats. Once expression tests false, the loop ends.