Loops
Every if statement has two branches even if it doesn't have an else body.
break
The break statement terminates the loop immediately and the control flows to the statement after the body of the loop
continue
The continue statement terminates the current iteration of the statement, skips the rest of the code in the current iteration and control flows to the next iteration of the loop
1) What is the difference between for loop and while loop in Python
For loop: Used when we know how many times to repeat, often with lists, tuples, sets, or dictionaries.
While loop: Used when we only have an end condition and don't know exactly how many times it will repeat.
for i in range(5):
print(i)
c = 0
while c < 5:
print(c)
c += 1
2) Can you write a for-loop that contains "break", "continue" and "pass" ?
MyList = [1,2,3,2,3,4,3,4,5,4]
for num in in MyList
pass
if (num == 0)
current = num
break
elif (num % 2 == 0)
continue
print(num)
print(current)
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext