You are on page 1of 17

Program Flow

Control
MR. MICHAEL ANGELO I. DUNGO
INSTRUCTOR I
If..elif..else

 A Block of code is a piece of program that is executed as an unit


 Python uses Identation to delimiter blocks of code. It uses 4 spaces
of indetation.
 If..elif.else

 If some_condition_is_true:
 Execute this code
 elif some_other_condition_is_true:
 Execute this code
 else:
 Execute this code
For loop

 For Loop means a possibility to execute repetitive task


 An object is iterable if we can iterate over that object
 If we have a collection of items, iterating over the collection means
a way to get items out of the collection one by one

iterable_object = [1,2,5,9]
for item in iterable_object:
print(item)
Range

 A Range is a type that represents an immutable sequence of


numbers and is commonly used for looping a specific number of
times in for loops.
 The built in function range() returns ranges of numbers
 Range(start, stop, step)
 By Default
 Start = 0
 Step = 1
 Start is included
 Stop is excluded
Continue

 The continue statement in Python returns the control to the


beginning of the loop. The continue statement rejects all the
remaining statements in the current iteration of the loop and moves
the control back to the top of the loop.

 The continue statement can be used in both while and for loops.
Break

 ‘Break’ in Python is a loop control statement. It is used to control the


sequence of the loop. Suppose you want to terminate a loop and
skip to the next code after the loop; break will help you do that. A
typical scenario of using the Break in Python is when an external
condition triggers the loop’s termination.
While

 While loop will continue to execute a block ofcode while some test
condition remains True

while some_Boolean_condition_is_true:
do something(while block of code)
else:
another block of code
While and Continue
While and Break

 Create a Program that Guess the lucky number between 1 to 20


GOOD DAY!
Stay Safe

You might also like