Flow control:
The flow control means which order to move forward in executing time is decided by flow control
flow controls are 3 statement types
1. Conditional Statements
2. Iterative Statements
3. Transfer Statements
1. Conditional Statements
1) if
2) if-elif
3) if-elif-else
2. Iterative Statements
1) for
2) while
3. Transfer Statements
1) break
2) continue
3) pass
and some are there like return and all we will update it later.
some valid points on flow control
There is no switch statement in python
do-while not in python
goto statement not in python.
before going to flow control we must focus on indentation.
Indentation means proper gap under the condition.
the indentation will help with simple readability and the code looks good.
Ex:
check the above example if the condition below the body is moving some tab gap and else under post-code with some tab gap. it means the body is under control on the if statement.
if the body starts with exactly under if then it's considered that it's not under control on the if statement.
nowadays smart IDE's are easily arranged in the indentation mode. but sometimes it may trouble.
if condition:
if condition: statement
OR
if condition :
statement-1
statement-2
statement-3
If..... the condition is true then statements will be executed.
Ex:
Enter number:400 #result
Yes your guess is correct
try one more time
2) if-else:
if condition:
Action-1
else:
Action-2
if the condition is true then Action-1 will be executed otherwise Action-2 will be executed.
Ex:
Result:
Enter number:10
your enter equal number
try one more time
if-elif-else:
if condition1:
Action-1
elif condition2:
Action-2
elif condition3:
Action-3
elif condition4:
Action-4
... else:
Default Action
Based on conditions the corresponding action will be executed.
Ex:
Enter the number on 0-9 only: 6 # Result
please try again
try one more time
Note:
1) else part is always optional. Hence the following are various possible syntaxes.
1) If
2) if – else
3) if-elif-else
4) if-elif
some examples of the above conditions
find the positive number or negative number?
enter the number: -567 # Result
-567 is a negative number
one more try
find the biggest numbers in 2 given numbers?
# Result
enter the number: 3
enter the number: -2
biggest number is 3
find the smallest numbers in 2 given numbers?
# Result
enter the number: 3
enter the number: -2
smallest number is -2
find the biggest numbers in 3 given numbers?
# Result
enter the number: 234
enter the number: 345
enter the number: 349
biggest number is 349
find the smallest numbers in 3 given numbers?
# Result
enter the number: 235
enter the number: 456
enter the number: 1234
smallest number is 235
Check the number in between (1-100) or not?
# Result
enter the number: 67
number 67 is in between 1-100
enter the number: 122
number 122 is not in between 1-100
Post a Comment