DEV Community

Saravanan B
Saravanan B

Posted on

Core Java - Flow Control

Flow control it will manage how the program flow has to go.

selection statements - if-else, switch
Iterative - while, do while, for, for-each.
Transfer statements - break, continue, return, try-catch-finally and assert.

If-else :
if(conditional expressions){
code to be executed;
} else{
code to be executed;
}

Nested If:
if(condition){
code to be executed;
}else if(condtion){
code to be executed;
}else{
code to be executed;
}

Image description

Switch Statements
switch(x)
{
case1:
Action1;
break;
case2:
Action2;
break;
default:
Default Action;
}

Image description

While
while(condition){
Body of the loop;
}

it will execute till the condition is false.

Image description

Do while
it will execute first and then check for the condition.
do{
execute the condition;
}while(condition);

Image description

For loop
is a looping statement if we know the number of iterations.
for(initialization;condition; increment or decrement){
loop body;
}

Image description

Top comments (0)