Control Structures - Formula Sheet
Control Structures Syntactic Formulas
1. Simple If Block
Structure:
if <condition>:
statements-block
Definitions:
- <condition>: A relational or logical comparison that yields a Boolean value.
- statements-block: Indented instructions that execute if the condition is True.
2. If-Else Alternative Selection
Structure:
if <condition>:
statements-block1
else:
statements-block2
Definitions:
- statements-block1: Executed when the condition evaluates to True.
- statements-block2: Executed when the condition evaluates to False.
3. Inline Ternary Conditional Assignment
Structure:
<variable> = <value1> if <condition> else <value2>
Definitions:
- <variable>: The target variable receiving the assignment.
- <value1>: Assigned to the variable if the condition is True.
- <condition>: The conditional Boolean expression.
- <value2>: Assigned to the variable if the condition is False.
4. Entry-Controlled While Loop
Structure:
while <condition>:
statements-block1
[else:
statements-block2]
Definitions:
- statements-block1: Repeatedly executed as long as the condition remains True.
- else: Optional block executed once when the loop condition evaluates to False.
5. Definite For Loop over a Sequence
Structure:
for counter_variable in sequence:
statements-block1
[else:
statements-block2]
Definitions:
- counter_variable: Temporary variable that holds the current item from the sequence on each pass.
- sequence: An ordered range, list, tuple, or string.
6. Range Function Parameters
Structure:
range(start, stop[, step])
Definitions:
- start: The starting integer of the sequence (inclusive). Defaults to 0.
- stop: The terminal limit of the sequence (exclusive). Values go up to stop - 1.
- step: The integer increment or decrement value. Defaults to 1.
More for this chapter
Book Back Questions10 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Science
View all
1 Function
2 Data Abstraction
3 Scoping
4 Algorithmic Strategies
5 Python -Variables and Operators
7 Python functions
8 Strings and String manipulation
9 Lists, Tuples, Sets and Dictionary
10 Python Classes and objects
11 Database Concepts
12 Structured Query Language (SQL)
13 Python and CSV files
14 Importing C++ programs in Python.
15 Data manipulation through SQL
16 Data visualization using pyplot: line chart, pie chart and bar chart