Circular outline
Looping statements
1.while Loop statement
The while Loop statement also becomes a conditional judgment statement, which loops in a condition that controls whether the statement continues to execute repeatedly. The syntax format is as follows:
while (conditional expression)
{
EXECUTE statement
}
Or
while (logical expression)
{
Code (EXECUTE statement)
Break
}
When the return value of the conditional expression is true, the return value of the conditional expression is re-judged after the statement in "{}" is executed, and the loop is exited until the result returned by the expression is false.
The parentheses of the while expression cannot be appended with ";"! Remember!!
2.do......while Loop Statements
The Do......while Loop statement is similar to the while loop, and the difference between them is that the while Loop statement is the first to judge whether the condition is set up and then executes the loop body, and the Do......while loop statement executes a loop before judging whether the condition is set. That is to say, the do......while in curly braces in the loop statement must be executed at least once. The syntax format is as follows:
Do
{
EXECUTE statement
}
One notable difference from the while statement is that the Do......while Loop statement has a semicolon (;)) at the end. The Do......while loop statement execution process is summarized according to the grammatical features of the Do......while Loop statement:
Do While
Do
{
System.out.println ("i=" +i);
i++;
}
while (I<10);
3.for Loop statement
The FOR Loop statement is one of the most useful looping statements in Java programming. A For loop can be used to repeatedly execute a statement, knowing that a condition is satisfied.
For statement
The syntax format is as follows:
for (expression 1; expression 2; expression 3;)
{
Statement sequence
}
Expression 1: Initializes an expression that is responsible for initializing the variable.
Expression 2: A loop condition expression that evaluates to a Boolean expression that specifies a loop condition.
Expression 3: The post-loop action expression, which is responsible for trimming the variable and changing the loop condition.
Execution of the For loop, the first execution of the expression 1, the initialization of a variable, the next step to determine the value of the expression 2, if the value of expression 2 is true, then enter the loop body, after the completion of the loop body immediately after the expression 3 is evaluated, which is usually an expression to increase or decrease the loop control variable. So the cycle is over. The second cycle begins with the expression 2, and if the expression 2 returns True, the loop continues, otherwise it jumps out of the entire for statement.
4. Other keywords
(1) Break statement
The break statement can also be used in the for, while, and Do......while loop statements to forcibly exit a loop, that is, to ignore any other statements in the loop body and the restrictions of the loop condition.
(2) Continue statement
The continue statement can only be applied in the for, while, and Do......while loop statements, allowing the program to skip directly behind the statement for the next loop.
Syntax Basics for Java 4