JAVA Statements
JAVA Statements
Syntax:
False
True
True False
Example: Read marks from user and state only if user is pass.
It is used to take decision based on a single condition
Syntax:
False
True
Flow Chart:
True False
The if else statement has one condition and two statement blocks-
True block and False block
Syntax:
Flow Chart:
True False
If within else
Example:
The Nested if can be inside the if-part or else-part
Syntax:
Flow Chart:
True False
If within else
Flow Chart:
True False
If within else
Example:
Example:
A switch statement is used to test many conditions
Syntax:
Start
Flow Chart:
Variable or Expression
… Case C Statements
True
False
End
Start
Flow Chart:
Variable or Expression
… Case C Statements
True break;
False
End
Example:
-In iti alizati on
-Con diti on ch ecking
-Executi on
-In crement / Decrement
Entry Controlled Exit Controlled
Condition is checked at the entry of the Condition is checked at the exit of the
loop loop
If condition is initially false, the loop If condition is initially false, then also the
never executes loop executes at least once
i=1; i=1;
while(i==0) do
{ {
System.out.println(“In While System.out.println(“In While loop”);
loop”); } while(i==0);
} System.out.println(“out of the loop”);
System.out.println(“out of the
loop”); Output:
In while loop
Output: Out of the loop
Out of the loop
Variable i in memory
Output Condition
is True
1
Variable i in memory
Check it
out here
Output
1
1
Variable i in memory
Check it
out Output
here
1
2
i
Variable i in memory
Output Condition is
checked again
1
2
Variable i in memory
Output Condition
is True
1
2
Variable i in memory
Check it
out here
Output
1
2 2
i
Variable i in memory
Check it
out Output
here
1
3 2
i
Variable i in memory
Output Condition is
checked again
1
3 2
i
Variable i in memory
Output Condition
is True
1
3 2
i
Variable i in memory
Check it
out here
Output
1
3 2
3
i
Variable i in memory
Check it
out Output
here
1
4 2
3
i
Variable i in memory
Output Condition is
checked again
1
4 2
3
i
Variable i in memory
Output Condition
is True
1
4 2
3
i
Variable i in memory
Check it
out here
Output
1
4 2
3
i
4
Variable i in memory
Check it
out Output
here
1
5 2
3
i
4
Variable i in memory
Output Condition is
checked again
1
5 2
3
i
4
Variable i in memory
This process will continue till the condition become false
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Output Final output of
the loop
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Initialization Statement is used to initialize a variable/ counter.
The condition statement controls the execution of loop
The loop executes till the condition statement is true
This section is used to increment or decrement the variable value
The execution statements are the main body of a loop
All action statements of loop are written here
Output Initialization
Variable i in memory
Condition
Output
is True
Variable i in memory
Check it
out here
Output
1
1
Variable i in memory
Check it increment
out Output
here
1
2
i
Variable i in memory
Condition is
Output checked again
1
2
Variable i in memory
Condition
Output
is True
1
2
Variable i in memory
Check it
out here
Output
1
2 2
i
Variable i in memory
Check it
out Output
here
1
3 2
i
Variable i in memory
Condition is
Output checked again
1
3 2
i
Variable i in memory
Condition
Output is True
1
3 2
i
Variable i in memory
Check it
out here
Output
1
3 2
3
i
Variable i in memory
Check it
out Output
here
1
4 2
3
i
Variable i in memory
Condition is
Output checked again
1
4 2
3
i
Variable i in memory
Condition
Output
is True
1
4 2
3
i
Variable i in memory
Check it
out here
Output
1
4 2
3
i
4
Variable i in memory
Check it
out Output
here
1
5 2
3
i
4
Variable i in memory
Output Condition is
checked again
1
5 2
3
i
4
Variable i in memory
This process will continue till the condition become false
1
10 2
3
i
4
5
Variable i in memory 6
7
8
9
Check it
out here
Output
1
10 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Check it
out Output
here
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Condition is
Output checked again
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Output Condition
is FALSE
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Output
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
Skip the body of
10
the lop and
executes the
statement just
after the loop
Final value of i
after the
complete loop Output
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Output Final output of
the loop
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Initialization Statement is used
to initialize a variable/ counter.
The condition statement controls
the execution of loop
Variable i in memory
No condition
Output checking at entry of
the loop
1
Variable i in memory
Check it
out here
Output
1
1
Variable i in memory
Check it
out Output
here
1
2
i
Variable i in memory
Output
1
2
i
Condition is
checked again
Variable i in memory
Output
1
2
i Condition
is True
Variable i in memory
Check it
out here
Output
1
2 2
i
Variable i in memory
Check it
out Output
here
1
3 2
i
Variable i in memory
Output
1
3 2
i Condition is
checked again
Variable i in memory
Output
1
3 2
i
Condition
is True
Variable i in memory
Check it
out here
Output
1
3 2
3
i
Variable i in memory
Check it
out Output
here
1
4 2
3
i
Variable i in memory
Output
1
4 2
3
i Condition is
checked again
Variable i in memory
Output
1
4 2
3
i
Variable i in memory
Check it
out Output
here
1
5 2
3
i
4
Variable i in memory
Output
1
5 2
3
i Condition is
4
checked again
Variable i in memory
This process will continue till the condition become false
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10
Output Final output of
the loop
1
11 2
3
i
4
5
Variable i in memory 6
7
8
9
10