1 5 1 P 603c5d760c516 File
1 5 1 P 603c5d760c516 File
Written by
Yogita Jore
Head, Department of Information Technology (NBA Accredited),
Vidyalankar Polytechnic, Mumbai
Unit Outcome 5:
Develop Programs using relevant
control structure to solve the given
problem.
Learning Outcome 5a:
Students should understand the use of
decision making statements.
What we will learn today-Decision Making Statements
Key takeaways
1. if statement
Where to use decision making statements in given problem?
2. if-else statement
3. if-else-if ladder
4. nested if statement
Yogita Jore
5. Switch case Head, Department of Information Technology (NBA Accredited), Vidyalankar Polytechnic,
Mumbai
► if statement
► if-else statement
► if-else-if ladder
► nested if statement
► Switch case
}
}
Page 8 Maharashtra State Board of Technical Education
Java if-else Statement
The Java switch statement executes one statement from multiple conditions.
It is like if-else-if ladder statement.
The switch statement works with byte, short, int, long, enum types, String and some wrapper types like Byte,
Short, Int, and Long.
In other words, the switch statement tests the equality of a variable against multiple values.
Syntax:
switch(expression)
{
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......
default:
code to be executed if all cases are not matched;
}
Page 13 Maharashtra State Board of Technical Education
Java switch Statement-Example
The break statement in java is used to terminate from the loop immediately.
When a break statement is encountered inside a loop, the loop iteration stops there, and control returns from
the loop immediately to the first statement after the loop.
Example:
public class BreakDemo
{
public static void main(String[] args)
{
for(int i=1;i<=10;i++)
{ if(i==8)
{
break;
}
System.out.println(i);
}
}
}
The continue statement in Java is used to skip the current iteration of a loop.
We can use continue statement inside any types of loops such as for, while, and do-while loop.
Example:
public class ContinueDemo
{
public static void main(String[] args)
{
for(int i=1;i<=10;i++)
{
if(i==5)
{
continue;
}
System.out.println(i);
}
}
}
Page 16 Maharashtra State Board of Technical Education