0% found this document useful (0 votes)
2 views1 page

Flow Control Py

Flow control statements in programming allow for decision making, looping, and branching, altering the standard top-to-bottom execution of code. There are three main types: conditional/decision-making statements, iterative/looping statements, and transfer statements, each serving distinct purposes in controlling code execution. Examples include using 'if' statements for conditions, 'for' and 'while' loops for repetition, and 'break' and 'continue' for altering loop behavior.

Uploaded by

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

Flow Control Py

Flow control statements in programming allow for decision making, looping, and branching, altering the standard top-to-bottom execution of code. There are three main types: conditional/decision-making statements, iterative/looping statements, and transfer statements, each serving distinct purposes in controlling code execution. Examples include using 'if' statements for conditions, 'for' and 'while' loops for repetition, and 'break' and 'continue' for altering loop behavior.

Uploaded by

mohit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Flow Control

The statements in your code are generally executed from top to bottom, in the order that they
appear. Control flow statements, however, break up the flow of execution by employing decision
making, looping, and branching, enabling your program to conditionally execute particular blocks
of code. We've 3 types of flow control statements -

Conditional/decision-making - Gives your code some decision making abilities, We can


control what statements get executed depending on a condition.
Iterative/looping - Help us repeat a piece of code for some number of times.
Transfer - These statements help us terminate a looping/iterative statement or skip a
certain iteration depending on some condition.
We can use these statements individually, or even combine them with one another.

CONDITIONAL / DECISION-MAKING STATEMENTS :

if (condition) : if (condition) : if (condition_one) :


dothistask dothistask dothistask
else : elif (condition_two) :
dothattask dothattask
else :
defaulttalk

name = input('Your name : ') name = input('Your name : ') name = input('Your name : ')
if (name == 'Python'): if (name == 'Python'): if (name == 'Python'):
print('Hi, Python') print('Hi, Python') print('Hi, Python')
else : elif (name == 'Java'):
print('Hi, User') print('Hi, Java')
else :
print('Hi, User')

ITERATIVE/LOOPING STATEMENTS :

for
# To perform a task specific number of times # To iterate over an iterable and perform a
task on each of its value

for i in range(number) : for each in iterable :


dothistask dothistask

for i in range(1,5): names = ['python', 'java', 'JavaScript']


print(i) for name in names:
print(name)

while
# 'While' continues testing the condition & executing its block until condition evaluates to false.

while (condition) :
dothistask
# infinite loop # finite loop

x=1 x=1
while(x<=3): while(x<=3):
print(x) print(x)
x = x+1
#11111...
#123

TRANSFER STATEMENTS :

break continue

for i in range(1,10): for i in range(1,10):


if i==5: if i==5:
break continue
print(i) print(i)

#1234 #12346789

You might also like