B2.3 Programming constructs - IB Diploma Class 11 Computer Science Notes, Diagrams and Solved Questions

How programs make decisions, repeat work and stay organised, in Python and Java: sequence, if and else-if chains, switch and match, for, while and do-while loops, nested loops with break and continue, and functions with parameters, return values and scope.

In this chapter

  • Sequence, selection and iteration as the building blocks of algorithms
  • if, else-if chains and nested selection
  • switch in Java and match in Python, and the fall-through bug
  • Count-controlled for loops and condition-controlled while and do-while loops
  • Nested loops, break and continue
  • Functions and methods: parameters, arguments and return values
  • Local and global scope, and the benefits of modularization
  • Iteration 3: passing arguments, sentinel loops, counting iterations and refactoring