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-