Control the execution flow
In Java, you use execution control statements to make choices.
4.1 true and false
All conditional statements use the truth or falsehood of the conditional expression to determine the execution path.
4.2 if-else
if(boolean-exp)
{
//dosomething
}else{
//dosomething
}
Boolean expressions must produce a boolean result.
4.3 Iteration
while, do-while, and for statements are used to control loops.
4.4 ForEach syntax
for(Obj obj: list) is used to loop over arrays and containers.
4.5 return
The return keyword is useful in two ways: on the one hand it specifies the method return value, on the other hand it causes the current method to exit and return that value.
4.6 break和continue
beak is used to force the loop to exit, and no longer execute the remaining statements in the loop.
continue stops the execution of the current iteration, and then returns to the beginning of the loop to start the next iteration.
Infinite loops: while(true) and for(;;)
4.8 switch statement
switch (key) {
case value:
break;
default:
break;
}
key must be an integer value (int or char).