Python
for loop
Saurabh Shukla (MySirG)
- Agendas
① for loop
② Practice program
③ For us while
⑥ break in for
⑤ for else
torloop
For loop only works on iterables .
for variable in Iterable :
code
code
Examine
" "
for x in My Sira :
print (se )
output in
y
s
i
r
G
Write to Count
'
a
program a'
in for loop
a
green string using .
)
"
"
input ( Enter
Si =
a
string
count = 0
for e in SI :
" "
a :
if e==
count -1--1
(
"
count
''
count )
print -_
,
whilevsfoo
while loop iterates a block of code
till the specified condition is true .
for loop iterates a block of code
number
number of times same as
the itesabhe
of elements in .
for deterrents of iterate
It iterates
element to the least
from first
element
[Link]
group of values
elements of the
to access
• Ability
the
( from first erdement
to
object
last element )
is applicable on
certain types
breakinfor
break keyword can be used only in
the body of loop ( while or for )
the control outside
break transfers
the loop body and loop terminates
for else
for variable in iterable :
code
code
if condition :
break
code
else :
code
code
Print all the character of a
string ,
but
if appeared the
' '
stop printing r in sequence .
If all the character successfully printed
characters
"
the print message All the are
processed
"
)
"
"
si = input ( Enter a
string
for e in SI :
' '
r :
if e = =
break
)
'
print ( e , end =
processed )
'
else : " characters are
( AM the
print
)
"
"
✗ = input ( Enter a
string
for I in x :
' '
if i r
= = :
break
)
' '
( i end
print
=
,
else :
processed )
"
"
All the characters
print (
are