Chap 2 Notes
Chap 2 Notes
me/+leBJyZDDoUw3NWRl
a=10
b=20
c=a+b
print(c)
2. Selection/ Decision: In this, program executes according to condition. If any
condition in true code will run if condition if false code will not run. Keyword If ,
else
1. if statement
2. if else statement
3. if elif else statement
4. Nested if-else statement
if statement:
The statements inside the body of “if” only execute if the given condition
returns true. If the condition returns false then the statements inside “if” are
skipped.
Syntax:
if test expression:
statement(s)
statement(s)
if else statement:
The if/else statement executes a block of code if a specified condition is
true. If the condition is false, another block of code can be executed.
Syntax:
if test expression:
Body of if
else:
Body of else
Syntax
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
1. for loop
2. while Loop
3. Nested for Loop
4. Nested while loop
Use of range()
range(start, stop, step)
Syntax:
while test expression:
Body of while
4. Jump Statement:
1. break statement
2. continue statement
3. pass
Break Statement: Break statement in Python is used to terminate the loop
when some external condition is triggered.
Continue Statement: The continue statement is used to skip the rest of the code
inside a loop for the current iteration only.
Pass Statement: The pass statement is a null operation, it does nothing, it is also
called empty statement.
l=[10,20]
for i in l:
pass