Posts

Showing posts with the label continue

Topic11: Pass, continue, break, and else in Python?

Loop Manipulation Using pass , continue , break , and else in Python In Python, loops are used to execute a block of code repeatedly until a specific condition is met. However, sometimes we need more control over how the loop behaves  for example, to skip certain iterations, stop the loop early, or execute a block after the loop ends. Python provides loop manipulation statements like pass , continue , break , and else to make loops flexible and powerful. 1. The pass Statement The pass statement does nothing,   it’s a placeholder that helps maintain syntactic correctness when a statement is required but no action is needed. Example: for i in range(5): if i == 3: pass # No action taken else: print("Value:", i) Output: Value: 0 Value: 1 Value: 2 Value: 4 Explanation: When i == 3 , Python executes pass and moves to the next iteration without doing anything. 2. The continue Statement The continue statement skips the remaining code ...