0% found this document useful (0 votes)
7 views5 pages

Chap 2 Notes

The document provides an overview of Python's control flow, including sequence statements, selection/decision statements, iteration/looping statements, and jump statements. It details the syntax and usage of various conditional statements such as if, if-else, if-elif-else, and nested if-else, as well as looping constructs like for and while loops. Additionally, it explains jump statements including break, continue, and pass, with examples for each type.

Uploaded by

Debu Nayak
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)
7 views5 pages

Chap 2 Notes

The document provides an overview of Python's control flow, including sequence statements, selection/decision statements, iteration/looping statements, and jump statements. It details the syntax and usage of various conditional statements such as if, if-else, if-elif-else, and nested if-else, as well as looping constructs like for and while loops. Additionally, it explains jump statements including break, continue, and pass, with examples for each type.

Uploaded by

Debu Nayak
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
You are on page 1/ 5

Click to join our Telegram group: https://t.

me/+leBJyZDDoUw3NWRl

Chapter 1: Python Revision Tour 2

Conditional Statement and Looping Statement

Flow of execution/Program Control and Flow


Control and flow of a program is classified into 4 categories:
1. Sequence Statement 2. Selection/Decision Statement
3. Iteration / Looping Statement 4. Jump Statement

1. Sequence: In this, program executes in sequential order, one after another,


without any jump in the program.

Ex: Program to calculate sum:

a=10
b=20
c=a+b
print(c)
2. Selection/ Decision: In this, program executes according to condition. If any
condition in true code will run if condition if false code will not run. Keyword If ,
else

Types of Decision making statement in python:

1. if statement
2. if else statement
3. if elif else statement
4. Nested if-else statement

if statement:
The statements inside the body of “if” only execute if the given condition
returns true. If the condition returns false then the statements inside “if” are
skipped.
Syntax:
if test expression:
statement(s)
statement(s)

if else statement:
The if/else statement executes a block of code if a specified condition is
true. If the condition is false, another block of code can be executed.
Syntax:
if test expression:
Body of if
else:
Body of else

if elif else statement:


The if-elif-else statement allows you to check multiple expressions for TRUE and
execute a block of code as soon as one of the conditions evaluates to TRUE.

Syntax

if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)

Nested if-else statement:


When you want to check for another condition after a condition resolves to
true. In such a situation, you can use the nested if else statement.

The syntax of the nested if...elif...else construct may be −


if expression1:
statement(s)
if expression2:
statement(s)
else:
statement(s)
else:
statement(s)

3. Iteration / Looping: In this statement program executes multiple times


according to condition. Keyword while, for

Types of looping statement in python:

1. for loop
2. while Loop
3. Nested for Loop
4. Nested while loop

For loop statement:


The for loop statement is used to iterate / repeat itself over a range of values or
a sequence. (That is either, a list, a tuple or a string).
Syntax:
for iterating_var in sequence:
statements(s)
statements(s)

Use of range()
range(start, stop, step)

While loop statement:


A while loop statement in python executes a block of code repeatedly as long as
the test/control condition of the loop is true.

Syntax:
while test expression:
Body of while

4. Jump Statement:

1. break statement
2. continue statement
3. pass
Break Statement: Break statement in Python is used to terminate the loop
when some external condition is triggered.

Break statement with for loop Syntax

for iterating_var in sequence:


if condition:
break
statements(s)

Continue Statement: The continue statement is used to skip the rest of the code
inside a loop for the current iteration only.

Continue statement with for loop Syntax

for iterating_var in sequence:


if condition:
continue
statements(s)

Pass Statement: The pass statement is a null operation, it does nothing, it is also
called empty statement.

l=[10,20]
for i in l:
pass

You might also like