Conditional and Looping Constructs
Conditional and Looping Constructs
Informatics
practices
Conditional
Class XI ( As per
CBSE Board)
&
Looping
Construct
New
s
Syllabus
2019-20
Flowchart
A flowchart is simply a graphical representation of steps. It shows steps in a
sequential order, and is widely used in presenting flow of algorithms, workflow
or processes. Typically, flowchart shows the steps as boxes of various kinds,
and their order by connecting them with arrows.
Flowchart Symbols
Different flowchart shapes have different conventional meanings. The
meanings of some of the more common shapes are as follows:
1. Terminator
The terminator symbol represents the starting or ending point of the system.
2. Process
A box indicates some particular operation.
3. Document
This represents a printout, such as a document or a report.
Flowchart
4. Decision
A diamond represents a decision or branching point. Lines coming out from
the diamond indicates different possible situations, leading to different sub-
processes.
5. Data
It represents information entering or leaving the system. An input might be an
order from a customer. An output can be a product to be delivered.
6. Flow
Lines represent flow of the sequence and direction of a process.
Flowchart
Flowchart for addition of
two numbers
y=2
if(x
==
1
and
y==
2):
p
ri
nt
(‘
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):
print(‘less than 100')
else:
print(‘more than equal 100')
OUTPUT
less than 100
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
Output
Inside loop
Inside
loop
…
…
e.g.
for i in range(3,5):
print(i)
Output
3
4
Iteration Statements (Loops)
2. For Loop continue
Example programs
for i in range(5,3,-1):
print(i)
Output
5
4
range() Function Parameters
start: Starting number of the sequence.
stop: Generate numbers up to, but not including this number.
step(Optional): Determines the increment between each
numbers in the sequence.
Iteration Statements (Loops)
2. For Loop continue
For Loop With Else
e.g.
for i in range(1, 4):
print(i)
else: # Executed because no break in
for print("No Break")
Output
1
2
3
No Break
Iteration Statements (Loops)
2. For Loop continue
Nested For Loop
e.g.
for i in range(1,3):
for j in range(1,11):
k=i*j
print (k, end=' ')
print()
Output
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16
18 20
Iteration Statements (Loops)
3. Jump Statements
print("The
end")
Output
s
t
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:
p
rint(i
)
OUTPU
T
n
t
a
L
NOTE : continue forces the loop to start at the next