LOOPS ALLOW EXECUTION A MULTIPLE TIMES. for loops while
for loop In Python for loop is used for iteration of a sequence. for loop continues the iteration till the sequence is ended. false <condition> true p o lo <statement block> exit the loop
for loop - Examples Reading a book on Loop continues off Loop ends As long as the lamp is on the loop continues so the loop here is reading a book. So the loop ends when light is switched off.
while loop In Python while loop is used when a certain block is to be executed until the condition in while statement is true. A loop become infinite if the condition never becomes false <condition> true p o lo Statement block of while Exit the while loop
while loop - Examples Driving Destination - 5 kms apart 2 km Still Loop continues 5 km Loop ends The distance is defined so here the while loop implements as long as the person doesn’t complete the distance they keep on driving until they reach the destination.
Nested loop Loop inside a loop. false outer loop condition false true inner loop condition Statement inside inner loop with incrementation End / stop
Nested loop - Examples Rising moon and setting of sun SUN SETS Loop ends MOON RISES Loop starts MOON SETS Another Loop ends