3. The following are the control
statements available in python:
If statements
If….else statement
If….elif…else statement
While loop
For loop
Break statement
Continue statement
Pass statement
Assert statement
Return statement
4. The if statement:
This statement is used to execute one or more
statement depending up on whether a condition is true
or not.
Syntax: if condition:
statements
code: num=1 output:
if num==1: one
print(“one”)
5. The if…else statement:
This statement execute the group of statements when a
condition is true, otherwise it will execute the else
statement.
Syntax: if condition:
statements
else:
statements
code: x=int(input(“enter the value”))
if x%2==0:
print(“even”)
else:
print(“odd”)
6. The if..elif..else statement:
The if..elif..else statement is used to execute the block of
statements among more than two condition.
Syntax: if condition1: code: num=5
statements1 if num==0:
elif condition2: print(“zero value”)
statement2 elif num<0:
elif condition3: print(“negative”)
statement3 else:
else: print(“positive”)
statement4
7. The while loop:
The while loop is useful to execute a group of
statement several times repeatedly depending up
on whether a condition is True or False.
Syntax: while condition:
statements
code: x=1
while x<=10:
print(“x=”,x)
x+=1
8. The for loop:
The for loop is useful to iterate over the
elements of a sequence.it means ,the for loop
can be used to execute a group of statement
repeatedly depending upon the number of
element in the sequence
syntax: for var in sequence:
statements
code: str=“hello”
for ch in str:
print(ch)
9. The break statement:
The break statement can be used Inside the a for loop or while
loop to come out of the loop. When ‘break’ is executed, the
python interpreter jumps out of the loop to process the next
statement in the program.
Syntax: while/for condition:
statements
code: x=0
while x<=10:
print(“x=”,x)
if x==5:
break
10. The continue statements:
The continue statement is used within loop to skip the
some part of the current iteration and move in to the next
iteration.
Syntax: while/for condition:
if condition:
continue
code: x=0
while x<=10:
print(“x=”,x)
if x==5:
continue
11. The pass statement:
The pass statement does not do anything. It is used with
‘if’ statement or inside the loop to represent no
operation. We use pass statement when we need a
statement syntactically but we do not want to do any
operation.
The assert statement:
The assert statement is useful to check if a particular
condition is fulfilled or not.
Syntax: assert expression, message
code: x=int(input(“enter the value greater than 0=”))
assert x>0, “wrong input entered”
print(“you entered:” ,x)
12. The return statement:
A return statement is used to end the execution
of the function call and “return”
the result.
Syntax: def fun()
statements
return expression
code: def cube(x):
r=x**3
return r