Computer ScienceClass 11Flow of Control

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 in Python: Class 11 NCERT Computer Science Guide

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

  • break exits the loop immediately.
  • continue skips 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:

ConstructPurposeUsage FrequencyExample Condition Check
ifExecutes block if condition trueSingle or first checkif x > 0:
if..elseTwo-way decisionWhen two outcomes existif x > 0: ... else: ...
if..elif..elseMultiple conditionsMultiple exclusive casesif 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..else to 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.

Open in ConceptScroll →

Study smarter with ConceptScroll

Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.

Start learning free
#class 11#computer science#flow of control#if else#loops#ncert#programming basics#python#selection statements

Continue reading