| The control statements provided in Java are basically used to cause the proper flow of execution in the advanced and branched Java programs.These control statements can be categorised into the following:
|
[edit] Java Selection Statements
|
Selection statements, as self explainatory helps the programmer to choose different paths of execution based upon the outcome of an expression or the state of a variable.
if(isOpen) { //isOpen is a boolean variable System. out. println("The Door is OPEN"); } else { System. out. println("The Door is CLOSE); }
|
|
|
[edit] Java Loops/Iteration Statements
|
| Iteration statements as the term states, is the repeatition of the block of code in a program.
|
int i = 1; while(i < 5) { System. out. println("The current value of variable i is " + i ); i = i + 1; }
|
|
|
[edit] Java Jump Statements
|
|
|
| Jump statements allow your program to execute in a nonlinear fashion.
|
// break is a jump statement int count = 5; while(true) { if(count == 5) { System. out. println("We will use break statement " + "to jump out of the while block"); break; } // code for some process. }
|
|
|