Control Structures – Sequence, Selection, Repetition, if-else & Loops
This article is a definition of terms for control structures – including exam questions and tags.
In a Nutshell
Control structures determine the flow of an algorithm through decisions, repetitions, and sequences. They are essential for controlling program logic.
Compact Technical Description
Control structures are fundamental building blocks in algorithms that control the flow of program execution. There are three main types: sequence (statements are executed in order), selection (e.g. if/else – decisions) and repetition (e.g. loops such as for or while). Through them, an algorithm can flexibly respond to different inputs or situations. Conditional statements allow you to take different paths depending on truth values. Loops make it possible to execute statements multiple times as long as a certain condition is met.
Exam-Relevant Key Points
- Three main types: sequence, selection, repetition
- Conditional branches: if, else if, else
- Loop types: for, while, do-while
- Control structures influence execution logic
- Loops should be terminated (exit condition)
Core Components
- Sequence (linear execution)
- Selection (e.g. if/else, switch)
- Repetition (e.g. while, for)
- Conditions (Boolean expressions)
- Loop control (break, continue)
Practical Example
// Example: Check if a number is even
if (number % 2 == 0) then
output("Number is even")
else
output("Number is odd")
Explanation: The modulo operator checks whether a number is divisible by 2 without remainder. Depending on the result, a corresponding message is output.
Advantages and Disadvantages
Advantages
- Increases code readability and structure
- Allows dynamic flows depending on condition
- Supports reusability through loops
Disadvantages
- Complex nested structures can become confusing
- Infinite loops possible with incorrect condition
- Error-prone when conditions are not correctly defined
Typical Exam Questions (with Brief Answer)
- Three types of control structures? Sequence, selection, repetition.
- if-branch used for? For conditional execution of statements based on a truth value.
- Differences between while and for-loop? for-loops contain initialization, condition, and increment; while-loops only the condition.
- “break” in a loop? Terminates the loop prematurely.
- Use do-while-loop? When the loop should run at least once.
- Avoid infinite loop? Through a meaningful exit condition within the loop.
- Role of conditions in control structures? Control whether and how often a particular code section is executed.
Most Important Sources
- https://de.wikipedia.org/wiki/Kontrollstruktur_(Programmierung)
- https://www.inf-schule.de/grundzuege/algorithmen/kontrollstrukturen
- https://www.w3schools.com/cs/cs_conditions.php