JAVA learning - loop flow control structure of

Concept cyclic structure:
loop structure, reacting a code structure or portion of code as many times as repeated in certain conditions.
Loop structure of the classification:

  • for loop
  • while loop
  • do ... while loop

for loop
format: for (execute statement; Analyzing conditional statement; control condition statements) {
// loop body
}
Here Insert Picture Description
the while loop
format:
initialization statement;
the while (judgment condition statement) {
loop statement;
controlling conditional statement;
}
Note:

  • Initialization statement can be omitted

  • Control condition statement may be omitted
    Here Insert Picture Description
    do while loop
    initialization statement;
    do {
    loop statement;
    controlling conditional statement;
    } the while (judgment condition statement);
    Note:

  • Parentheses following the semicolon can not be omitted while

  • do ... while loop the loop statement is executed at least 1 times

Two kinds of infinite loop

  • for( ; ; ){
    }
  • while( true){
    }

break
interrupt, for switch statements and loops;
end of the switch block ends the loop and
Here Insert Picture Description
continue
to continue to loop, indicating the end of this cycle, the next cycle continues
Here Insert Picture Description

Nested loop
when the loop statement contains another statement in a loop, known as nested loops.

Reference numeral
i.e. rotation name, as needed or jump to the end of the specified cycle. Commonly used in the nested loop.Here Insert Picture Description
Here Insert Picture Description

Random class
for generating a random number category.
Format:
Import java.util.Random; // leader packet
Random r = new Random (); // create objects Random class
int number = r.nextInt (10); a random number between 0 and 9 // Get random number

Released nine original articles · won praise 1 · views 176

Guess you like

Origin blog.csdn.net/LQyh_/article/details/104051334