Python program to illustrate
# combining else with for
list
=
[
"geeks"
,
"for"
,
"geeks"
]
for
index
in
range
(
len
(
list
)):
print
(
list
[index])
else
:
print
(
"Inside Else Block"
)
Output:
geeks
for
geeks
Inside Else Block
# Python program to illustrate
# nested for loops in Python
for
i
in
range
(
1
,
5
):
for
j
in
range
(i):
print
(i, end
=
' '
)
print
()
Output:
1
2 2
3 3 3
4 4 4 4
# Prints all letters except 'e' and 's'
for
letter
in
'geeksforgeeks'
:
if
letter
=
=
'e'
or
letter
=
=
's'
:
continue
print
(
'Current Letter :'
, letter)
var
=
10
for
letter
in
'geeksforgeeks'
:
# break the loop as soon it sees 'e'
# or 's'
if
letter
=
=
'e'
or
letter
=
=
's'
:
break
print
'Current Letter :'
, letter
No comments:
Post a Comment