Professional Documents
Culture Documents
FS20CO047
Experiment 7
Title:
Write a program to demonstrate the use of if and if else
Theory:
1. if statement
An if statement consists of a boolean expression followed by one or
more statements.
2. if else statement
An if statement can be followed by an optional else statement , which
executes when the boolean expression is false .
Break statement:
The break statement is used to break out of a loop. It is used inside for and
while loops to alter the normal behaviour. break will end the loop it is in and
control flows to the statement immediately below the loop.
Syntax:
for i in range(1, 11):
if i == 7:
break
print(i)
print("Loop terminated")
3 Python Experiment NO 07
Continue statement:
The continue keyword is used to end the current iteration in a for
loop or a while loop, and continues to the next iteration. The
continue statement is used to skip the rest of the code inside a loop
for the current iteration only. Loop does not terminate but
continues on with the next iteration.
Syntax:
for i in range(1, 11):
if i == 7:
continue
print(i)
Return statement:
The return statement is used inside a function to exit it and return a
value. If you won't return a value explicitly, None is returned
automatically in Python.
Syntax:
def funtion_name():
statements
.
.
.
return [expression]
4 Python Experiment NO 07
Pass statement:
The pass statement is a null operation; nothing happens when it
executes. The pass is also useful in places where your code will
eventually go, but has not been written yet.
Syntax:
def func1(args):
pass
class Person:
pass
print("Successfully Executed")
Practical:
a. Check given Number is odd or even.
Program:-
Observation:
a.
Output:-
b.
Output:-
6 Python Experiment NO 07
Conclusion:
In the above programs I have learnt the use of if else statements .
It helps to give the conditions in the program.