while与do while

First, the general form of the while statement is: 
while (expression) statement
where the expression is the loop condition, and the statement is the loop body.
The semantics of the while statement is: evaluate the value of the expression, and when the value is true (not 0), execute the loop body statement.

2. The general form of the do-while statement is:
do
statement
while (expression);
the difference between this loop and the while loop is that it first executes the statement in the loop, and then judges whether the expression is true, and if it is true, it continues loop; if false, terminates the loop. Therefore, the do-while loop executes the loop statement at least once .
The following points should be paid attention to when using the while statement:
1. The expression in the while statement is generally a relational expression or a logical expression . As long as the value of the expression is true (not 0), the loop can continue.
2. If the loop body includes more than one statement, it must be enclosed in {} to form a compound statement.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324929450&siteId=291194637