Flow of Control in Python: Class 11 NCERT Computer Science Guide
By ConceptScroll Team · Published on 17 July 2026 · 5 min read

Flow of Control determines how a program executes instructions based on conditions and loops. In Class 11 NCERT Computer Science, mastering this concept helps you write efficient Python programs that make decisions and repeat tasks.
Understanding Flow of Control in Python
Flow of Control in programming is the order in which individual statements, instructions, or function calls are executed or evaluated. In Python, this flow can be controlled using decision-making statements and loops. For Class 11 NCERT students, this concept is fundamental to writing programs that respond differently based on inputs or conditions.
Python executes code sequentially by default. However, using Flow of Control, you can change this sequence to make your program dynamic and interactive. This includes:
- Selection (Decision Making): Choosing between different paths.
- Iteration (Loops): Repeating a block of code multiple times.
Mastering these constructs allows you to write programs like calculators, games, and data processors that behave intelligently.
Selection Statements: Making Decisions in Python
Selection statements let programs choose between different actions based on conditions.
if Statement
The simplest selection statement is if. It executes a block only if a condition is true.
``python if condition: # statements ``
Example: ``python num = 10 if num > 0: print("Positive number") ``
if..else Statement
Allows two alternative paths:
``python if condition: # statements if true else: # statements if false ``
Example: ``python num = -5 if num >= 0: print("Non-negative") else: print("Negative") ``
if..elif..else Statement
Used for multiple conditions:
``python if condition1: # block1 elif condition2: # block2 else: # block3 ``
Example: ``python color = 'red' if color == 'red': print("Stop") elif color == 'yellow': print("Get Ready") else: print("Go") ``
Nested if Statements
You can place an if or else inside another if or else for finer control.
Proper indentation is critical to define these blocks in Python.
Want to test yourself on Flow of Control? Try our free quiz →
Iteration: Repeating Actions with Loops
Loops allow repeating a block of code multiple times, which is essential for tasks like processing lists or running a program until a condition changes.
while Loop
Repeats as long as a condition is true.
``python while condition: # statements ``
Example: ``python count = 1 while count <= 5: print(count) count += 1 ``
for Loop
Used to iterate over a sequence (like a list or range).
``python for variable in sequence: # statements ``
Example: ``python for i in range(1, 6): print(i) ``
break and continue
breakexits the loop immediately.continueskips the current iteration and continues with the next.
Example: ``python for i in range(5): if i == 3: break # stops loop when i is 3 print(i) ``
Loops combined with selection statements control program flow effectively.
Comparison of Selection Constructs in Python
Here's a quick comparison of the main selection statements used in Python:
| Construct | Purpose | Usage Frequency | Example Condition Check |
|---|---|---|---|
| if | Executes block if condition true | Single or first check | if x > 0: |
| if..else | Two-way decision | When two outcomes exist | if x > 0: ... else: ... |
| if..elif..else | Multiple conditions | Multiple exclusive cases | if x>0: ... elif x==0: ... else: |
Use elif to check multiple conditions sequentially. Use else as a default fallback.
Worked Example: Positive Difference Calculator
Let's create a program that calculates the positive difference between two numbers, demonstrating selection and flow of control.
```python num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: "))
if num1 > num2: diff = num1 - num2 else: diff = num2 - num1
print("Positive difference is", diff) ```
Explanation:
- The program reads two numbers.
- Uses
if..elseto decide which number to subtract from which. - Ensures the difference is always positive.
This example shows how selection controls the flow based on conditions.
Practical Application: Simple Calculator Program
A simple calculator demonstrates multiple selection conditions and error handling.
```python num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) operator = input("Enter operator (+, -, *, /): ")
if operator == '+': result = num1 + num2 elif operator == '-': # positive difference if num1 > num2: result = num1 - num2 else: result = num2 - num1 elif operator == '': result = num1 num2 elif operator == '/': if num2 != 0: result = num1 / num2 else: result = "Error: Division by zero" else: result = "Invalid operator"
print("Result:", result) ```
This program uses nested if statements and multiple selection paths to perform calculations and handle errors.
Frequently asked questions
What is the difference between else and elif in Python?
Else executes when all if and elif conditions are false, acting as a default. Elif checks multiple conditions sequentially and can be used multiple times.
How does the range() function work in Python loops?
Range() generates a sequence of numbers from start (inclusive) to stop (exclusive), used to control loop iterations.
What is the purpose of break and continue statements?
Break exits a loop immediately, while continue skips the current iteration and moves to the next.
What is an infinite loop? Give an example.
An infinite loop runs endlessly because its condition never becomes false, e.g., while True: print("Looping")
Why is indentation important in Python flow of control?
Indentation defines blocks of code belonging to conditions or loops; incorrect indentation causes errors or logic faults.
Ready to ace this chapter?
Get the full Flow of Control chapter — interactive notes, diagrams, worked solutions, polls and a free practice quiz — in the ConceptScroll app.
Study smarter with ConceptScroll
Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.
Start learning freeContinue reading
- Understanding Societal Impact: Class 11 NCERT Computer Science Guide
Discover how digital technologies shape society and the responsibilities of netizens in Class 11 NCERT Computer Science. Understand the societal impact for safer online use.
- Understanding Societal Impact in Computer Science for Class 11 NCERT
This blog explains the societal impact of computer science for Class 11 NCERT students, focusing on digital footprints, privacy, and ethical use of technology.
- Understanding Societal Impact in Class 11 Computer Science
This blog explains the societal impact of technology, data protection, and intellectual property rights for Class 11 NCERT Computer Science students.