Module Name - Conditionals, Loops & Functions Class - Day 3 Topic Name-Loops
Module Name - Conditionals, Loops & Functions Class - Day 3 Topic Name-Loops
●
●
●
int bricks = 0;
while(bricks < 100) // loop will continue as long as
// this condition is satisfied
{
“Pick up brick”
“Keep it on wall”
bricks = bricks + 1; // value of bricks variable is
} // incremented by 1
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
Infinite while Loop: Example
●
●
for(__;__;__;)
{
code...
}
●
int i=0 // value of i is 0 initially.
●
i<10 // Program will be in loop as long as
// this condition remains satisfied
●
i++ // This will increment the value of i by 1
Check for all numbers between [1 -100]
If even -> Print
Else -> Do not print
Move on to next number
for( int i=1; i<=100; i++ ) {
if( i%2 == 0 )
{
System.out.print( i );
}
}
●
●
●
●
while Loop for Loop
FOR WHILE
Even Numbers Example using while Loop
Java Code: For Loop
●
●
●
●
Java Code: For Loop
●
●
●
●
●
●
do{
Code statements…
}
while( condition )
Java Code: Do While Loop
●
●
●
●
Pseudocode: Array Initialization with For Loop
●
●
●
●
●
●
for( int i= 1; i<3500; i++) {
if(i%2==1) // It means i is odd.
{
continue;
}
System.out.print(i);
}
●
●
●
●
#LifeKoKaroLift
Thank you!