Saturday, August 8, 2020

Comparisons and Loops with break/Continue


# Comparisons:


# Equal: ==
# Not Equal: !=
# Greater Than: >
# Less Than: <
# Greater or Equal: >=
# Less or Equal: <=
# Object Identity: is



Break statement :


nums = [1,2,3,4,5]

for num in nums:

if num == 2:

### Here we are breaking out of while loop when num is equal to 2, output will only be 1
break
print(num)
num += 1



Continue statement :

nums = [1,2,3,4,5]

for num in nums:

if num == 2:

### Here we are passing off when num is equal to 2, so output is 1,3,4,5
continue
print(num)
num += 1



No comments:

Post a Comment