← Computer Studies / 3 Software development
3.4 Control Structures
Computer Studies · Grade 10 · 17 lessons in the design
What this covers
- The three control structures: sequence, selection, iteration
- Boolean and compound expressions
- Selection: if, if-else, if-elif-else and nested if
- Iteration: while loops and for loops
- The break and continue statements
- Choosing the right control structure
What you will be able to do
- describe control structures in programming
- select the program control structure for a given situation
- use control structures in programming
- appreciate the application of control structures in programming
Key questions
“How are Boolean expressions used in programming?”
“What is the importance of control structures in programming?”
Lessons
The titles are open to everyone. Reading a lesson needs an account — sign in or create one.
-
Selection: making decisions
40 min · 1 practice tasks · quizHow a program chooses between paths using if, if-else and if-elif-else, tested by Boolean and compound expressions.
-
Iteration: loops, break and continue
40 min · 1 practice tasks · quizRepeating steps with while and for loops, the danger of the infinite loop, and controlling loops with break and continue.
-
Sequence: steps in order
40 min · 1 practice tasks · quizSequence is a control structure: do this, then that. A kiosk change program with no extra rules is pure sequence.
-
How Boolean expressions are used in control
40 min · 1 practice tasks · quizEvery if and while tests a Boolean expression from 3.3. True takes a path; False skips or takes the other.
-
Compound Boolean expressions in real rules
40 min · 1 practice tasks · quizand, or and not inside if: teenager discounts, weekend fares, valid marks. Range uses and; alternatives use or.
-
The simple if: one optional path
40 min · 1 practice tasks · quizif condition: indented block. True runs it; False skips it. Nothing else happens. Indentation is the syntax.
-
if-else: two paths, one of them always runs
40 min · 1 practice tasks · quizif-else chooses between two complete answers: pass or fail, enough tendered or ask for more, PIN right or wrong.
-
if-elif-else: several bands, first True wins
40 min · 1 practice tasks · quizelif means else if. Tests run top to bottom. Grade bands and fare bands must be ordered from the most demanding down.
-
Nested if: a decision inside a decision
40 min · 1 practice tasks · quizThe inner if is reached only if the outer condition was True. Login then role; valid mark then pass. Indentation shows the nest.
-
Flowcharts for selection
40 min · 1 practice tasks · quizOval, parallelogram, rectangle, diamond. Every diamond has two labelled exits. Draw pass/fail and a grade chain before coding.
-
while loops: repeat until something happens
40 min · 1 practice tasks · quizwhile tests a Boolean before each round. Use it when the count is unknown: PIN, sum until 0. Update the variable or it never ends.
-
for loops and range: a known number of times
40 min · 1 practice tasks · quizfor walks through a collection. range(1, 6) is 1 to 5. Use for when you know the count or have a list of names.
-
Nested loops: a loop inside a loop
40 min · 1 practice tasks · quizThe inner loop finishes all its rounds for each outer round. Times tables, a seating grid, every learner on every day.
-
break: leave the loop immediately
40 min · 1 practice tasks · quizbreak jumps out of the current loop, even if rounds remain. Use it to stop at the first match in a register.
-
continue: skip this round, not the loop
40 min · 1 practice tasks · quizcontinue jumps to the next repetition. Use it to ignore absentees, hidden files, or a number you do not want to print.
-
Choosing the right control structure
40 min · 1 practice tasks · quizMatch the situation: sequence if no choice and no repeat; if/elif for a choice; for a known count; while until something happens.
-
Combining sequence, selection and iteration
40 min · 1 practice tasks · quizA real kiosk or class-fee program nests all three. That is why control structures are the grammar of programming.