← 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.

  1. Selection: making decisions
    40 min · 1 practice tasks · quiz
    How a program chooses between paths using if, if-else and if-elif-else, tested by Boolean and compound expressions.
  2. Iteration: loops, break and continue
    40 min · 1 practice tasks · quiz
    Repeating steps with while and for loops, the danger of the infinite loop, and controlling loops with break and continue.
  3. Sequence: steps in order
    40 min · 1 practice tasks · quiz
    Sequence is a control structure: do this, then that. A kiosk change program with no extra rules is pure sequence.
  4. How Boolean expressions are used in control
    40 min · 1 practice tasks · quiz
    Every if and while tests a Boolean expression from 3.3. True takes a path; False skips or takes the other.
  5. Compound Boolean expressions in real rules
    40 min · 1 practice tasks · quiz
    and, or and not inside if: teenager discounts, weekend fares, valid marks. Range uses and; alternatives use or.
  6. The simple if: one optional path
    40 min · 1 practice tasks · quiz
    if condition: indented block. True runs it; False skips it. Nothing else happens. Indentation is the syntax.
  7. if-else: two paths, one of them always runs
    40 min · 1 practice tasks · quiz
    if-else chooses between two complete answers: pass or fail, enough tendered or ask for more, PIN right or wrong.
  8. if-elif-else: several bands, first True wins
    40 min · 1 practice tasks · quiz
    elif means else if. Tests run top to bottom. Grade bands and fare bands must be ordered from the most demanding down.
  9. Nested if: a decision inside a decision
    40 min · 1 practice tasks · quiz
    The inner if is reached only if the outer condition was True. Login then role; valid mark then pass. Indentation shows the nest.
  10. Flowcharts for selection
    40 min · 1 practice tasks · quiz
    Oval, parallelogram, rectangle, diamond. Every diamond has two labelled exits. Draw pass/fail and a grade chain before coding.
  11. while loops: repeat until something happens
    40 min · 1 practice tasks · quiz
    while tests a Boolean before each round. Use it when the count is unknown: PIN, sum until 0. Update the variable or it never ends.
  12. for loops and range: a known number of times
    40 min · 1 practice tasks · quiz
    for walks through a collection. range(1, 6) is 1 to 5. Use for when you know the count or have a list of names.
  13. Nested loops: a loop inside a loop
    40 min · 1 practice tasks · quiz
    The inner loop finishes all its rounds for each outer round. Times tables, a seating grid, every learner on every day.
  14. break: leave the loop immediately
    40 min · 1 practice tasks · quiz
    break jumps out of the current loop, even if rounds remain. Use it to stop at the first match in a register.
  15. continue: skip this round, not the loop
    40 min · 1 practice tasks · quiz
    continue jumps to the next repetition. Use it to ignore absentees, hidden files, or a number you do not want to print.
  16. Choosing the right control structure
    40 min · 1 practice tasks · quiz
    Match the situation: sequence if no choice and no repeat; if/elif for a choice; for a known count; while until something happens.
  17. Combining sequence, selection and iteration
    40 min · 1 practice tasks · quiz
    A real kiosk or class-fee program nests all three. That is why control structures are the grammar of programming.