2. Introduction
• Control statements are used in programming
languages to cause the flow of control to
advance and branch based on changes to the
state of a program.
3. Introduction
• In Java, control statements can be divided
under the following three categories:
• Selection statements
• Iteration statements
• Jump statements
5. • Selection statements are used in a program to
choose different paths of execution based
upon the outcome of an expression or the
state of a variable.
6. Using if and if...else
• Syntax: if ( Expression ) Statement
• Semantics: The expression must be of type
boolean. If it evaluates to true, the given
statement is executed, otherwise not.
7. Using if and if...else
• Note that there is only one statement. To
execute more than one statement
conditionally, a block statement is to be used.
8. Using if and if...else
• In addition, our coding standard expects following
layout:
if ( Expression ) {
Statement1
}
elseif ( Expression ){
Statement 2
}
else{
Statement 3(default value)
}
9. Example Program
• Write a program that display grade as PASSED
if value is greater than or equal to 75,
otherwise, FAILED.
10. Solution
public class Grades{
public static void main (String [] args){
int grade;
grade = 10;
if(grade >=75) {
System.out.println(“PASSED”);
}
else if(grade < 75){
System.out.println(“FAILED”);
}
else{
System.out.println(“ ”);
}
}
}