What Is a Control Structure?
A control statement is a statement that determines the control flow of a set of instructions. A
control structure is a set of instructions and the control statements controlling their execution.
Three fundamental forms of control in programming are sequential, selection, and iterative
control.
• Sequential control is an implicit form of control in which instructions are executed in
the order that they are written.
• Selection control is provided by a control statement that selectively executes
instructions.
• iterative control is provided by an iterative control statement that repeatedly executes
instructions.
Indentation in Python
• A header in Python is a specific keyword followed by a colon.
• The set of statements following a header in Python is called a suite(commonly called
a block).
• A header and its associated suite are together referred to as a clause.
Selection Control or Decision Making statement
A selection control statement is a control statement providing selective execution of
instructions.
• if statements
• if-else statements
• Nested if statements
• Multi-way if-elif-else statements
if statement:
• An if statement is a selection control statement based on the value of a given Boolean
expression.
• The if statement executes a statement if a condition is true.
1
, PROBLEM SOLVING USING PYTHON
Details of the if Statement
Points to Remember
• A colon (:) must always be followed by the condition.
• The statement(s) must be indented at least one space right of the if statement.
• In case there is more than one statement after the if condition, then each statement
must be indented using the same number of spaces to avoid indentation errors.
• The statement(s) within the if block are executed if the boolean expression evaluates
to true.
Flow Chart for if statement
Example :
num1=eval(input(“Enter First Number: “))
num2=eval(input(“Enter Second Number: “))
if num1-num2==0:
print(“Both the numbers entered are Equal”)
Output :
Enter First Number: 12
Enter Second Number: 12
Both the numbers entered are Equal
2