Jump Statements

Jump statements such as break, continue, and pass.

Python - Jump Statements:

There are several ways to control the flow of your program using statements like 'break', 'continue', and 'pass'. These are often referred to as "jump statements" as they allow you to jump to different parts of your code. Here's a brief explanation of each:

1. break: This statement is used to exit from a loop prematurely. When 'break' is encountered inside a loop, the loop is terminated immediately, and the program control resumes at the next statement following the loop.

PDF Copy Code
# Python: The 'break' statement
for i in range(5):
    if i == 3:
        break
    print(i)
Output:
0
1
2

2. continue: This statement is used to skip the rest of the code inside a loop for the current iteration and jump to the next iteration of the loop.

PDF Copy Code
# Python: The 'continue' statement
for i in range(5):
    if i == 2:
        continue
    print(i)
Output:
0
1
3
4

3. pass: This statement is a null operation; nothing happens when it executes. It's often used as a placeholder where code will eventually go or in situations where the syntax requires a statement but you don't want any action to be taken.

PDF Copy Code
# Python: The 'pass' statement
for i in range(5):
    if i == 2:
        pass  # Placeholder for future code
    else:
        print(i)
Output:
0
1
3
4

These jump statements provide flexibility in controlling the flow of your code within loops and conditional blocks.

What's Next?

We've now entered the finance section on this platform, where you can enhance your financial literacy.