0% found this document useful (0 votes)
8 views

Unit-3 Iterative Statements in Python.ppt

The document provides an overview of iterative statements in Python, focusing on for loops and while loops, including their syntax and examples. It covers the 'in' operator, the range() function, and concepts like infinite loops, break, continue, and pass statements. Additionally, it includes learning objectives and references for further study.

Uploaded by

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

Unit-3 Iterative Statements in Python.ppt

The document provides an overview of iterative statements in Python, focusing on for loops and while loops, including their syntax and examples. It covers the 'in' operator, the range() function, and concepts like infinite loops, break, continue, and pass statements. Additionally, it includes learning objectives and references for further study.

Uploaded by

kalyani sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

ASSISI CONVENT SCHOOL

Iterative Statements in Python

Unit-3
Class-VIII

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL

Index
• Learning Objective • Examples of
• Introduction to iterat While loop using else
ive statements in Pyt statement in Python
hon • Infinite loop in Pytho
• For statement n
• Example of for loop • Examples of Infinite
• in operator in Python lbreak statement in
python
• Example of “in” Oper • jump statement in py
ator thon
• range() function in • break statement in p
Python ython
• Examples of range() f • Examples break state
unction in Python ment in python
• While statement in P • continue statement i
ython n python
ASSISI CONVENT SCHOOL, NOIDA
ASSISI CONVENT SCHOOL
Index
Learning Objectives
• Understanding for statement.
• Understanding While statement.
• Explaining While using else
statement.
• Using Python infinite loop.
• Understanding the jump statement.

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Introduction to iterative
statements in Python
In Python, an iterative
statement (also known as a
loop) is a control flow
statement that allows the
programmer to execute a block
of code repeatedly until a
certain condition is met. There
are two types of iterative
statements in Python: 1. `for`
loop: This loop is used for
iterating over a sequence

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

For statement
The For Loops in
Python are a special
type of loop statement
that is used for
sequential traversal.
Python For loop is used
for iterating over an
iterable like a String,
Tuple, List, Set, or
Dictionary.
ASSISI CONVENT SCHOOL, NOIDA
ASSISI CONVENT SCHOOL
Index
Example of for loop

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

in operator in Python
The 'in' operator in Python is
straightforward to use. It
checks whether a value
exists in a sequence (such as
a list, tuple, or string) and
returns a Boolean value:
True if the value is in the
sequence, and False if it's
not.

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

Example of “in” Operator

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
range() function in Python
The range() function returns a
sequence of numbers,
starting from 0 by default,
and increments by 1 (by
default), and stops before a
specified number.

Syntax
range(start, stop, step)

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Examples of range() function in Python
Example 1 Example 2

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
While statement in Python
Python While Loop is used to
execute a block of statements
repeatedly until a given condition
is satisfied. When the condition
becomes false, the line
immediately after the loop in the
program is executed.

Syntax of while loop in Python

while expression:
statement(s)

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Example of While loop
Example 1 Example 2

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
While loop using else statement in Python

In Python, the while else


statement is a combination
of a while loop with an else
block. The while loop
executes a block of code as
long as its given condition
remains true. Once the
condition becomes false,
the loop stops, and the else
block is executed.

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Examples of While loop using else statement in Python
Example 1 Example 2

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Infinite loop in Python

An infinite loop in Python is


a programmatic construct
that keeps running
indefinitely, without ever
reaching a terminating
condition. It is typically
used when the
programmer wants a piece
of code to repeat itself
continuously until a certain
external event occurs or a
specified condition
becomes true
ASSISI CONVENT SCHOOL, NOIDA
ASSISI CONVENT SCHOOL
Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Examples of Infinite loop in Python
Example 1 Example 2

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Example of break, continue and pass statements

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
Video-

ASSISI CONVENT SCHOOL, NOIDA


ASSISI CONVENT SCHOOL
Index
References
• https://www.youtube.com/watch?v=6iF8Xb7Z3wQ
• https://cbseskilleducation.com/introduction-to-
artificial-intelligence-class-9/
• Tech bits book- Class VIII

ASSISI CONVENT SCHOOL, NOIDA

You might also like