Course Content
Python Loops Tutorial
Python Loops Tutorial
Pass, Else in a for Loop
The pass
statement in Python is a null statement. It serves as a placeholder and does nothing when executed.
Examine the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] counter = 0 for i in numbers: # I will write the code here later pass
We've covered the if/else
construct.
Moreover, in Python, the for
loop can also include an else
block, which executes when the loop completes its iterations without any premature termination.
Look at the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] # Printing all elements of the list for i in numbers: print(i) else: print('Done')
Task
- Configure the
for
loop to operate onnumbers
, withi
as an element of the list. - Place
pass
within the else condition block.
Thanks for your feedback!
Pass, Else in a for Loop
The pass
statement in Python is a null statement. It serves as a placeholder and does nothing when executed.
Examine the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] counter = 0 for i in numbers: # I will write the code here later pass
We've covered the if/else
construct.
Moreover, in Python, the for
loop can also include an else
block, which executes when the loop completes its iterations without any premature termination.
Look at the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] # Printing all elements of the list for i in numbers: print(i) else: print('Done')
Task
- Configure the
for
loop to operate onnumbers
, withi
as an element of the list. - Place
pass
within the else condition block.
Thanks for your feedback!
Pass, Else in a for Loop
The pass
statement in Python is a null statement. It serves as a placeholder and does nothing when executed.
Examine the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] counter = 0 for i in numbers: # I will write the code here later pass
We've covered the if/else
construct.
Moreover, in Python, the for
loop can also include an else
block, which executes when the loop completes its iterations without any premature termination.
Look at the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] # Printing all elements of the list for i in numbers: print(i) else: print('Done')
Task
- Configure the
for
loop to operate onnumbers
, withi
as an element of the list. - Place
pass
within the else condition block.
Thanks for your feedback!
The pass
statement in Python is a null statement. It serves as a placeholder and does nothing when executed.
Examine the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] counter = 0 for i in numbers: # I will write the code here later pass
We've covered the if/else
construct.
Moreover, in Python, the for
loop can also include an else
block, which executes when the loop completes its iterations without any premature termination.
Look at the code below:
numbers = [2, 3, 8, 5, 6, 7, 8, 11, 8] # Printing all elements of the list for i in numbers: print(i) else: print('Done')
Task
- Configure the
for
loop to operate onnumbers
, withi
as an element of the list. - Place
pass
within the else condition block.