Controls the order of execution of statements.
Control Structures:
Sequence structure: Executes statements in order.
Decision structure: Executes actions based on conditions (Also known as selection structure).
Boolean Expression: Tested to check if it is true or false (e.g., a > b).
Relational Operators:
> - greater than
< - less than
>= - greater than or equal to
<= - less than or equal to
== - equal
!= - not equal
Structure:
Syntax: if condition: statements else: other statements
Executes one of two paths based on condition (true/false).
Strings compared using ==, !=, >, < based on ASCII values.
Case sensitive: e.g., 'abc' > 'Abc'.
A structure containing another decision structure.
Syntax: Nested if
statements should maintain proper indentation.
A simplified version of nested structures allowing multiple conditions.
Syntax:
if condition_1:
statements
elif condition_2:
statements
else:
statements
Logical Operators: Create complex Boolean expressions.
and
: True if both operands are true.
or
: True if at least one operand is true.
not
: Reverses Boolean value of the operand.
Within a Range: Use and
(e.g., x \geq 10 \text{ and } x \leq 20).
Outside a Range: Use or
(e.g., x < 10 \text{ or } x > 20).
Represents two values: True or False.
Often used as flags to signal conditions in programs.
Flag set to False: Condition does not exist.
Flag set to True: Condition exists.