-
Procedure
-
Sequence of steps that should be performed.
-
Well designed program consists of smaller independent parts.
-
These independent parts should be executed in some order.
-
Control structure defines in which order program is going to be executed.
-
First do this, then do this, after do that…
-
If some condition is met, do this. Otherwise do that.
-
Sequence logic, or sequential flow
-
Selection logic, or conditional flow
-
Iteration logic, or repetitive flow
- Top to bottom
- Sequence of steps that should be executed
-
If statement
-
If-else statement
-
Switch - does not exist in python. Can be replicated by else-if statement.
-
For loop
-
While loop
-
Do loop - does not exist in python. Can be made using for or while statement.
-
Every control structure consists of two parts:
- Head
- Body
-
How are head and body separated?
-
Can there be more than one head/body?
-
Head and body are separated by colon and indentation.
-
There can be more than one head/body.If-else statement.
-
Head
- Contains sth that evaluates to boolean
-
Body
- Contains set of instructions that should be performed if head evaluates to true
- Break: stop loop cycle when condition is met
- Continue: just continue execution of program to next interation. Code after 'continue' keyword will be ignored
- Pass: Do sth when condition is met, but code after 'pass' keyword will not be ignored