Page 188 - ComputerScience_Class_11
P. 188
To handle such flow of control, “if” and “switch case” statements are used.
Conditional Statement
if statement Switch Case
if-else statement
if and only if statement
if else if statement
nested if statement
Let us see in detail.
if Statement
This statement checks a particular condition. If the condition is satisfied, then the statement or a group of statements
inside the “if” block will be executed.
Syntax:
if(Condition)
{
Statement 1;
Statement 2;
.
.
}
Note: If there is single statement after the condition, then use of curly brackets is optional.
Flowchart:
True
Condition?
Statement
False
For example,
1. if(a%5==0)
System.out.println(a+ " is divisible by 5");
Here, the control statement checks whether the number stored in the variable a is divisible by 5. If it is divisible, the
message will be printed, otherwise, the message will be ignored.
186 Touchpad Computer Science (Ver. 3.0)-XI

