This is one of the important skeleton of the Code. It is easy to use and you may not want to write this description at the beginning. However, it may be convenient for you to study your homework in the future. It is also okay to simply write it.
1. While statement, basic form: While (expr) stmt
Note: When the while statement is executed, the expr is first evaluated. If the result is true, the while statement is terminated when the cyclic body stmt is executed. If the value is false, the while statement is terminated, continue to execute the next statement of the while statement. After each execution of the stmt loop body, the conditional expression expr will be re-evaluated, and then the result determines whether to continue to execute the stmt or terminate the while statement.
While (expr)
...{
Stmt1
.....
Stmtn
}
2. Loop Control statementsBreakAndContinue
The break statement causes the control flow of the program to jump out of the loop and execute the next statement of the while statement. Note that executing break only exits the loop of the innermost layer, instead of the loop of the outermost layer.
The continue statement causes the next loop to be executed in advance.
3. do_while statement, basic form: Do stmt while (expr)
Note: the flow direction of the do_while statement is to first execute the loop body, and then determine the result of the evaluation of the conditional expression. If the result is true, the execution of the loop body continues, otherwise, end the loop and execute a statement.
4. Equivalent operations of while and
Int counter = 0;
While (counter <n)
...{
Stmt
Counter = counter + 1;
}
For (INT counter = 0; counter <n; counter = counter + 1) stmt