0% found this document useful (0 votes)
16 views3 pages

Python Flow of Control Explained

The document explains the flow of control in Python, detailing sequential execution, conditional statements, loops, and loop control statements. It covers how Python executes instructions top-to-bottom by default, and how to use constructs like if, for, and while to manage the flow. Additionally, it introduces the 'pass' statement as a placeholder for syntactical requirements without action.

Uploaded by

Manivasakan P
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Python Flow of Control Explained

The document explains the flow of control in Python, detailing sequential execution, conditional statements, loops, and loop control statements. It covers how Python executes instructions top-to-bottom by default, and how to use constructs like if, for, and while to manage the flow. Additionally, it introduces the 'pass' statement as a placeholder for syntactical requirements without action.

Uploaded by

Manivasakan P
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Flow of Control in Python - Notes

1. What is Flow of Control?

Flow of control means the order in which instructions are executed in a Python program. By default, Python

follows top-to-bottom execution, but we can control the flow using decision making, looping, and loop control

statements.

2. Sequential Flow

Python executes instructions one after another, by default.

Example:

a = 10

b=5

print(a + b)

3. Conditional Statements

Used to execute code based on certain conditions.

-> if: Executes block if condition is True

Syntax: if x > 0:

print('Positive')

-> if-else: One block if True, another if False

Syntax: if x%2==0:

print('Even')

else:

print('Odd')

-> if-elif-else: Checks multiple conditions

Syntax: if marks>=90:

print('A')

elif marks>=75:

print('B')

else:

print('C')

4. Loops (Iteration)
Flow of Control in Python - Notes
Used to repeat a block of code multiple times.

-> for loop: When number of repetitions is known

Syntax: for i in range(5):

print(i)

-> while loop: When repetitions depend on a condition

Syntax: i = 1

while i <= 5:

print(i)

i += 1

5. Loop Control Statements

Used to control the execution within loops.

-> break: Exits the loop immediately

Syntax: if i == 3:

break

-> continue: Skips current iteration

Syntax: if i == 2:

continue

-> else with loop: Executes if loop finishes normally

Syntax: for i in range(3):

print(i)

else:

print('Loop done')

6. pass Statement

Used as a placeholder when a statement is required syntactically but no action is needed.

Example: if x < 0:

pass

7. Summary

Sequential - Default execution flow


Flow of Control in Python - Notes
Conditional - Decision making (if, elif, else)

Looping - Repeating code (for, while)

Loop Control - Control loop behavior (break, continue, else)

Placeholder - Empty block (pass)

You might also like