Flow of Control Flashcards
What is flow of control
Controlling flow of code in python
Input function?
Asking user to input value.
Syntax of input function?
<variable>= <datatype>(input(<enter>))
</enter></datatype></variable>
Type of flow of control?
→Sequential flow (line after line) Ex:
a= input(“enter:”)
b= “world”
print(a+b)
→Conditional flow ( Executed based on condition)
Iterative loops
Used to iterate an element in a sequence
s= “hello”
for i in s
print (i)
what is Range?
Used to **generate sequence of numbers **
in for a loop
for i in range (1,11)
print (i)
Write programme to generate first 10 odd numbers
for i in range (1,11)
if i%2==1:
print (i)
print(len(s))
calculates length of characters of elements
What is while loop?
Used to execute a block of code as long as the condition is true
example:
i=0
while i<=20
print(i)
i+=2
what does break do?
**Used to exit loop **when given condition is true
example:
for i in range(10)
print (i)
if i==5:
break
Continue:
**skips current iterations **if the condition is true and executes next iterations