Skip to content
Computing · JC 1 · Programming Constructs and Data Structures · Semester 1

Core Programming Fundamentals: Control Structures

Mastering conditional statements (if/else) and loops (for/while) to build interactive applications.

MOE Syllabus OutcomesMOE: Programming Constructs and Data Structures - JC1

About This Topic

Linear data structures like arrays, stacks, queues, and linked lists are the essential ways we organize data in memory. Each structure has its own strengths and weaknesses depending on the task at hand. For example, a stack is perfect for managing 'undo' operations, while a queue is ideal for handling print jobs or customer service lines. Understanding these structures allows students to write code that is both memory-efficient and logically sound.

In the Singapore context, these structures are used in everything from the backend of the Singpass app to the scheduling systems for the MRT. Students learn to implement these structures from scratch, which gives them a deep understanding of how memory is managed at a low level. This topic comes alive when students can physically model the patterns using physical objects to represent data nodes.

Key Questions

  1. Compare the behaviour of a while loop and a for loop , under what conditions would you choose each?
  2. Trace the execution of a nested if/else block and predict the output for a given set of inputs.
  3. Explain what happens when a loop condition never evaluates to false, and how you would detect and prevent this in your code.

Learning Objectives

  • Compare the execution flow and termination conditions of `while` and `for` loops.
  • Trace the step-by-step execution of nested `if/else` statements with given inputs and predict the final output.
  • Analyze the consequences of an infinite loop condition and propose methods to detect and prevent it.
  • Design a simple program that utilizes both conditional statements and loops to achieve a specific interactive outcome.

Before You Start

Introduction to Programming Concepts

Why: Students need a basic understanding of variables, data types, and assignment statements before they can control program flow.

Basic Operators

Why: Understanding comparison operators (>, <, ==, !=) and logical operators (AND, OR, NOT) is essential for forming the conditions used in control structures.

Key Vocabulary

Conditional StatementA programming construct that executes a block of code only if a specified condition is true. Examples include `if`, `else if`, and `else`.
LoopA programming construct that repeatedly executes a block of code as long as a specified condition remains true or for a set number of iterations. Examples include `for` and `while`.
IterationA single execution of the code block within a loop. The loop continues to perform iterations until its termination condition is met.
Boolean ExpressionAn expression that evaluates to either `true` or `false`. These expressions are fundamental for controlling the flow of conditional statements and loops.
Infinite LoopA loop whose termination condition is never met, causing it to execute indefinitely. This is typically an error that can freeze a program.

Watch Out for These Misconceptions

Common MisconceptionAn array and a linked list are basically the same thing.

What to Teach Instead

Arrays have fixed sizes and contiguous memory, while linked lists are dynamic and use pointers. Hands-on modeling of 'inserting' an item into the middle of an array versus a linked list shows the difference in effort required.

Common MisconceptionStacks and queues are only useful for simple tasks.

What to Teach Instead

These structures are fundamental to complex systems like operating system schedulers and expression parsing. Peer teaching about 'real-world stacks' (like the back button in a browser) helps students see their ubiquity.

Active Learning Ideas

See all activities

Real-World Connections

  • Game development heavily relies on control structures. For instance, a `while` loop might manage the main game loop, continuing as long as the player is alive, while `if/else` statements determine character actions based on player input or game state.
  • Automated systems in Singapore's Changi Airport, such as baggage handling or flight information displays, use complex control structures. `For` loops might process each item in a baggage queue, and `if/else` logic directs bags to the correct destination based on flight details.

Assessment Ideas

Quick Check

Present students with a code snippet containing a nested `if/else` structure and a specific input value. Ask them to write down the predicted output and briefly explain their reasoning for each step of the conditional evaluation.

Exit Ticket

On an index card, ask students to write: 1) One scenario where a `for` loop is more appropriate than a `while` loop. 2) One potential consequence of an infinite loop and a simple way to avoid it.

Discussion Prompt

Facilitate a class discussion using this prompt: 'Imagine you are debugging a program that seems to be running forever. What are the first steps you would take to identify if an infinite loop is the cause, and how would you modify the loop condition or body to fix it?'

Frequently Asked Questions

Why do we learn to implement data structures manually if Python has built-in lists?
Manual implementation teaches students about memory management, pointers, and the underlying logic of how data is stored. This foundational knowledge is crucial for optimizing performance in complex systems where built-in tools might be inefficient.
What is the most difficult data structure for JC1 students?
Linked lists are often the most challenging because they require a solid grasp of pointers and dynamic memory. Visualizing the 'links' between nodes is key, which is why physical modeling is so effective for this specific topic.
What are the best hands-on strategies for teaching linear data structures?
Using physical props like Pringles cans for stacks (LIFO) or a line of people for queues (FIFO) provides immediate visual and kinesthetic understanding. For linked lists, using index cards and actual pieces of string to represent pointers allows students to 'see' the connections and understand what happens when a link is broken or redirected.
How do data structures relate to Big O notation?
Every data structure has different Big O costs for operations like searching, insertion, and deletion. For example, searching an unsorted array is O(n), while pushing to a stack is O(1). Understanding these costs is essential for choosing the right structure.