In this section, we are going to discuss the control statements. Different types of control statements: the decision making statements (if-then, if-then-else and switch), looping statements (while, do-while and for) and branching statements (break, continue and return).
Control Statements
The control statement are used to controll the flow of execution of the
program . This execution order depends on the supplied data values and the conditional logic. Java contains the
following types of control statements:
1- Selection Statements
2- Repetition Statements
3- Branching Statements
Selection statements:
| int n = 10;
if(n%2 = = 0){ System.out.println("This is even number"); } |
| int n = 11;
if(n%2 = = 0){ System.out.println("This is even number"); } else{ System.out.println("This is not even number"); } |
| int day = 5;
switch (day) { |
Repetition Statements:
| int i = 1;
//print 1 to 10 while (i <= 10){ System.out.println("Num " + i); i++; } |
| int i = 1;
do{ System.out.println("Num: " + i); i++; }while(i <= 10); |
| for (int num = 1; num <= 10;
num++){
System.out.println("Num: " + num); } |
Branching Statements:

|
Recommend the tutorial |













Ask Questions? Discuss: Java Control Statements View All Comments
Post your Comment