java unusual common flow control statements

Although these statements are not common but can in some cases play out his useless, not bad not only for the flow control statements, too, foreach statement

Java5 introduced enhanced for loop for one of the main array.

grammar

for (declaration: expression) {

// Code sentence

}

Disclaimer statement: declare a new local variable, and the type of the variable must match the type of array elements. Loop whose scope is defined in the block, and its value is equal to the array element at that time.

Expression: Expression is the name of the array to be accessed, or method that returns the value of the array.

while statement

while loop is a prior condition for judgment, the conversion to a Boolean value of true, then the corresponding code is executed, then determination, then execute code statements;

Loop: repeat one thing;

while      do…while

while (conditional expression) {

loop statement;

}

Circulation circumstances require attention:

1, requires a condition for the loop;

2, the need to control the number of cycles;

do{

loop statement;

} While (conditional expression);

Features do ... while statement: no matter whether the conditions are met, will be executed at least once;

While using the local loop should be noted

Use a while loop must be the end of the statement cycle, otherwise it is infinite loop, such as the following cycle is dead, its condition judgment is always true, the code will always be executed, you can not end:

do-while loop Introduction

do-while loop and the while loop, loop are different in that, while loop condition is to be determined, the determination performed when true, do-while loop is executed once before the code (whether conditions is true or false) then conditional judgment is true will continue, false to immediately stop;

to sum up

The so-called flow control statements, is to control code execution order of statements, if the switch statement to select the program branch presence, for the program and while statements in the case of satisfying a condition of doing the same thing.

Guess you like

Origin blog.csdn.net/weixin_44589117/article/details/89602669