About the Do/While Statement
The do/while statement is very similar to while. The only difference is the order in which expression and statement are evaluated. This statement has the following format:
The do/while statement first executes statement and then evaluates expression. If expression is true, the process repeats. If expression is false, the loop terminates.
Do/while always executes statement at least once, even if expression is false the first time it is evaluated. In contrast, while executes statement only after expression evaluates true.
You can alter the previous example, which adds the square of all integers between 1 and 10, to use the do/while statement as follows: