CS101 - Introduction to Programming
CS101 - Introduction to Programming
Lecture 4 - Control Structures
Prof. Dr. James O'Connor
I. What are Control Structures?
Control structures determine the flow of a program's execution.
II. Conditional Statements
- if Statement: Executes a block of code if a condition is true.
- if-else Statement: Provides an alternative block if the condition is false.
- if-elif-else Ladder: Allows multiple conditions to be tested.
III. Loops
- for Loop: Iterates over a sequence.
- while Loop: Continues as long as a condition is true.
- break and continue statements: Control loop execution.
IV. Importance
Mastering control structures is fundamental to writing effective and efficient code.
V. Example Code
```
for i in range(5):
print("Hello, world!")
```
Reading:
- Chapter 3, Python Programming: An Introduction to Computer Science by John Zelle.