6.2.2 Using programming constructs:

Cards (99)

  • What are the three main programming constructs?
    Sequence, Selection, Iteration
  • What does the selection construct depend on?
    A condition
  • Match the programming construct with its definition:
    Sequence ↔️ Instructions executed in order
    Selection ↔️ Code based on a condition
    Iteration ↔️ Code repeated until a condition
  • What type of programming construct uses the keyword 'if'?
    Selection
  • Programming constructs enhance efficiency and improve readability

    True
  • The sequence construct ensures instructions are executed in a specific order
  • Iteration allows repetitive tasks to be automated
    True
  • Match the programming construct with its definition:
    Sequence ↔️ Instructions executed in order
    Selection ↔️ Code based on a condition
    Iteration ↔️ Code repeated until a condition
  • Give an example of a selection in code.
    `if x > 0: print("Positive")`
  • Programming constructs provide a framework for structuring code and controlling flow

    True
  • The sequence construct ensures instructions are executed in a specific order
  • What does the iteration construct improve in programming?
    Efficiency
  • Match the programming construct with its benefit:
    Sequence ↔️ Organizes instructions in order
    Selection ↔️ Enables conditional execution
    Iteration ↔️ Automates repetitive tasks
  • A `while` loop repeats code as long as a condition is true

    True
  • An `if` statement executes code only if a condition is true.

    True
  • A `for` loop repeats code a fixed number of times.

    True
  • A `do-while` loop repeats code at least once, then continues as long as a condition is true.
    True
  • Sequences make code easy to read and ensure instructions follow a logical flow
  • Match the programming construct with its definition:
    Sequence ↔️ Executes instructions in order
    Selection ↔️ Executes code based on a condition
    Iteration ↔️ Repeats a block of code
  • Programming constructs enhance code readability and enable reusability
  • Steps in an `if-elif-else` statement
    1️⃣ Check the first condition
    2️⃣ If true, execute the corresponding code
    3️⃣ If false, check the next condition
    4️⃣ Continue checking conditions until one is true
    5️⃣ If no condition is true, execute the `else` block
  • A sequence construct ensures instructions are executed in the order they are written.
    True
  • An `if-elif-else` statement allows checking multiple conditions
  • The main types of selection constructs are `if`, `if-else`, and `if-elif-else`
  • The `if-else` statement executes a different block of code if the condition is false.

    True
  • The key benefit of using selection constructs is the conditional execution of code
  • What does the `break` statement do in a loop?
    Terminates the entire loop
  • What are data structures used for in programming?
    Organizing and storing data
  • What is a key property of arrays in terms of element access?
    Constant-time access
  • Trees are commonly used for file systems and decision making.
    True
  • The sequence construct executes instructions in the order they are written
  • Iteration allows repetitive tasks to be automated, reducing the potential for errors.
    True
  • Programming constructs improve efficiency, readability, and reusability
  • Match the programming construct with its benefit:
    Sequence ↔️ Organizes instructions in a specific order
    Selection ↔️ Enables conditional execution of code
    Iteration ↔️ Automates repetitive tasks
  • What is the primary benefit of iteration in programming?
    Automating repetitive tasks
  • The selection construct in the Python code demonstrates the power of controlling the flow
  • Match the iteration construct with its termination condition:
    `for` loop ↔️ Reaches the end of iterations
    `while` loop ↔️ Condition becomes false
  • What does the `break` statement do in a loop?
    Terminates the entire loop
  • What are the key benefits of using a sequence construct?
    Clarity and predictability
  • Loop structures are used for repetitive execution of a block of code.
    True