3 Python Control
3 Python Control
of Flow
Python Control Flow
statements
>>>
break and continue
You can use the keyword break inside a
loop to leave the while loop entirely.
Output
Decision making
while loop
Repeats a statement or group of statements while
a given condition is true. It tests the condition
before executing the loop body.
for loop
Execute a sequence of statements multiple times
and abbreviates the code that manages the loop
variable.
nested loops
You can use one or more loop inside any another
while, for or do..while loop.
While loop example
The else Statement Used with Loops
Python For-loop statements
The for loop in Python has the ability to iterate
over the items of any sequence, such as a
list ,string, tuple and other built-in iterables.
output
Continue statement example
Pass statement example
for pnum in [1,2, -1, 3]:
if pnum < 0:
pass
else:
print pnum
Output
1
2
3
Exercises
Write a python program to check for validity of
password using if statement
Write a python program to check the eligibility for
voting using if-else
Write a python program to print student garde
using elif
Write a python program to find the factorial of
number using while loop
Write a python program to add 10 numbers by
inputting each from the keyboard using for loop
Write a python program to print string or number
is a palindrome or not.
Steps to install IDLE IDE for
python
For linux / Fedora users
#yum install python-tools