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

Grade 7 Python For Loop

The document covers Python for loops, explaining their use for iterating over sequences like lists, tuples, and strings. It introduces the break and continue statements for controlling loop execution, as well as the else clause that runs after a loop completes. Additionally, it discusses nested loops and provides a programming task to find prime numbers using a nested while loop.

Uploaded by

zawad12222009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Grade 7 Python For Loop

The document covers Python for loops, explaining their use for iterating over sequences like lists, tuples, and strings. It introduces the break and continue statements for controlling loop execution, as well as the else clause that runs after a loop completes. Additionally, it discusses nested loops and provides a programming task to find prime numbers using a nested while loop.

Uploaded by

zawad12222009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Module A

Lecture Topics: For Loop


Python For Loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Looping Through a String


Even strings are iterable objects, they contain a sequence of characters.

The Break Statement


With the break statement we can stop the loop before it has looped through all the items.
Example 01:

Example 02:
The continue Statement
With the continue statement we can stop the current iteration of the loop, and continue with the next.

Else in For Loop


The else keyword in a for loop specifies a block of code to be executed when the loop is finished.

Example 01:

Example 02:

Nested Loops
A nested loop is a loop inside a loop.
The "inner loop" will be executed one time for each iteration of the "outer loop".

The End
Write a Program use a nested while loop to find the prime numbers from 2 to 100.

-The End-

You might also like