Do While Loop

In most computer programming languages, a do while loop, sometimes just called a while loop, is a control flow statement that allows code to be executed once based on a given Boolean condition. Note though that unlike most languages, Fortran's do loop is actually the same to the for loop.

The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do while loops check the condition after the block is executed, the control structure is often also known as a post-test loop. Contrast with the while loop, which tests the condition before the code within the block is executed.

It is possible, and in some cases desirable, for the condition to always evaluate to true, creating an infinite loop. When such a loop is created intentionally, there is usually another control structure (such as a break statement) that allows termination of the loop.

Some languages may use a different naming convention for this type of loop. For example, the Pascal language has a "repeat until" loop, which continues to run until the control expression is true (and then terminates) — whereas a "while" loop runs while the control expression is true (and terminates once the expression becomes false). Bash did not support this control flow statement.

Read more about Do While Loop:  Equivalent Constructs, Demonstrating Do While Loops