Class11 - CS - Control Statements7class11 - CS - Control Statements7
Class11 - CS - Control Statements7class11 - CS - Control Statements7
Statements New
syllabus
2023-
24
Computer Science
Class XI
Control Statements
y=2
if(x
==1
an
d
y==
2):
p
ri
n
t(
‘c
o
n
di
ti
Decision Making Statement
2. if-else Statements
If-else statement executes some code if the test
expression is true (nonzero) and some other code if
the test expression is false.
Decision Making Statement
2. if-else Statements
Syntax:
if(condition):
statements
else:
statements
e.g.
a=10
if(a
<
100)
:
pri
nt(
‘le
ss
th
an
10
Decision Making Statement
1. While Loop
2. For Loop
x=1
while (x < 3):
print('inside while loop value of x is ',x)
x=x+1
else:
print('inside else value of x is ', x)
Output
inside while loop value of x is 1
inside while loop value of x is
2 inside else value of x is 3
*Write a program in python to
find out the factorial of a given
number
Iteration Statements (Loops)
While Loop continue
Infinite While Loop
e.g.
x=5
whil
e (x
==
5):
pri
nt(
‘in
sid
e
lo
op
')
Iteration Statements (Loops)
2. For Loop
It is used to iterate over items of any sequence, such as a list
or a string.
Syntax
for val in sequence:
statements
e.g.
for i in range(3,5):
print(i)
Output
3
4
Iteration Statements (Loops)
Output
5
4
range()
Functi
on
Param
eters
start:
Starting
Iteration Statements (Loops)
Output
1
2
3
No
Break
Iteration Statements (Loops)
Output
123456789
10
2 4 6 8 10 12 14
16 18 20
Iteration Statements (Loops)
3. Jump Statements
print("Th
e end")
Outp
ut s
t
r
Iteration Statements (Loops)
2.continue
It is used to skip all the remaining statements
in the loop and move controls back to the top of
the loop.
e.g.
for val in "init":
if val == "i":
continue
print(val)
print("The
end")
Output
n
t
The end
Iteration Statements (Loops)
3. pass Statement
This statement does nothing. It can be used when a
statement is required syntactically but the program
requires no action.
Use in loop
while True:
pass # Busy-wait for keyboard interrupt (Ctrl+C)
In function
It makes a controller to pass by without executing any code.
e.g.
def myfun():
pass #if we don’t use pass here then error message will be shown
print(‘my program')
OUTPUT
My program
Iteration Statements (Loops)
3. pass Statement continue
e.g.
for i in 'initial':
if(i == 'i'):
pass
else:
print(i)
OUTPUT
n
L
N
O