Control Structures Python Notes
Control Structures Python Notes
ITERATION OR LOOPING
ITERATION
3. ITERATION OR LOOPING
while loop
for loop
while loop
OUTPUT
for LOOP
OUTPUT
for LOOP - range KEYWORD
x = range(3, 6)
for n in range(3,6):
OR for n in x:
print(n)
print(n)
for LOOP - range KEYWORD
OUTPUT
for LOOP - range KEYWORD
#Generating even numbers
OUTPUT
for LOOP - range KEYWORD
# print string character by character
OUTPUT
else statement in loop
1. break STATEMENT
Loop
Condition ? break
causes
jump
True
Statement 1
break
1. break STATEMENT
OUT PUT
2. continue STATEMENT
Loop False
Condition ?
True
Statement 1
Statements
ignored or continue
skipped
continue
Statement n
causes
jump
2. continue STATEMENT
break continue
Difference Between break and continue
BREAK CONTINUE
It terminates the execution It terminates only the current
of remaining iteration of iteration of the loop.
the loop.
'break' resumes the control 'continue' resumes the control
of the program to the end of the program to the next
of loop enclosing that iteration of that loop enclosing
'break'. 'continue'.
It causes early termination It causes early execution of the
of loop. next iteration.
'break' stops the 'continue' do not stops the
continuation of loop. continuation of loop, it only
stops the current iteration.