# Create a list of numbers
nums = [1, 2, 3, 4, 5]
print(nums)
[1, 2, 3, 4, 5]
for
loop to print each element# Loop through the list and print out each number
for i in range(len(nums)):
print(nums[i])
1
2
3
4
5
i
i = 0
while
loop to print each elementi
variable inside loopi
is equal to the length of the listwhile i != len(nums):
print(nums[i])
i += 1
1
2
3
4
5
i
i = 0
break
to exit the loop early once i
reaches a particular valuebreak
statementwhile i != len(nums):
if i == 3:
'Exiting the loop.'
break
print(nums[i])
i += 1
1
2
3
i
i = 0
continue
to skip over a particular indexwhile i != len(nums):
if i == 3:
'Skipping element at index 3.'
i += 1
continue
print(nums[i])
i += 1
1
2
3
5