Switch/While/Do while/Debug
Narayan Niroula
1
2
A switch statement starts with an expression whose type isan
int, short, char, byte (or their wrapper type), String, or an
enum .
Local variable
3
Switch inside Switch
4
Example with boolean
5
While Loop
While
Condi
tion
Body code
Update
counter
False
True
Exit
6
While Loop
While
Condi
tion
Body code
Update
counter
False
True
Exit
int a = 10;
while(a<=15) {
System.out.println(a);
//a++;
what happens ?
}
7
Do …while
Do
body code
Cond
ition
Exit
False
True
int a = 10;
do {
//int a = 10; //what happens if
you here?
System.out.println("Inside do
loop body");
a--;
}while(a>1);
8
Entry level loop Exit level loop
Entry level loop is a loop in
which the test condition is
checked first, and then loop
body will be executed
Exit level loop is loop in which
the loop body is executed and
then the given condition is
checked afterward
If the test condition is false , loop
body will be executed
If the test condition is false, the
loop body will be executed at
least once
For loop and while loop are of
this type
Do—while is of this type
use it where you have to check
the condition is mandatory
Use it where check condition is
mandatory after execution
9
Working on rows and column
10
Debug 1
11
Debug 2
12
Debug3
int num1, num2,;
num1 = 30;
num2 = 50;
System.out.println("Before swapping : num1, num2 = "+num1+", "+
+ num2);
temp = num1;
num1 = num2;
num2 = temp;
System.out.println("After swapping : num1, num2 = "+num1+", "+ +
num2);
}
13
Debug 4
What is the output?
14
Continue and break
15

Day 5.pptx