1.1.4 Control structures

Cards (72)

  • Control structures determine the flow of execution
  • Control structures allow programs to make decisions and repeat code blocks.
  • Arrange the basic types of control structures in their typical order of use in a program.
    1️⃣ Sequential execution
    2️⃣ Branching
    3️⃣ Loops
  • Match each control structure with its description.
    Sequential Execution ↔️ Executes instructions in order
    Branching ↔️ Executes code selectively
    Loops ↔️ Repeats code blocks
  • Sequential execution executes instructions in the order they appear
  • Sequential execution ensures that each instruction builds upon the previous one.
  • Conditional statements use boolean expressions that evaluate to either true or false
  • An `if` statement executes a block of code only if its condition is true.
  • An `else` statement executes a block of code when the `if` condition is false
  • Arrange the three basic types of control structures in their order of description in the study material.
    1️⃣ Sequential execution
    2️⃣ Branching
    3️⃣ Loops
  • Sequential execution requires specific keywords to control its flow.
    False
  • In sequential execution, instructions are performed from top to bottom
  • What is the order of execution in sequential execution?
    Top to bottom
  • In the example x = 5; y = x + 10; print(y);</latex>, the final value of `y` is 15
  • Conditional statements execute code based on specific conditions.
  • Match the conditional statement with its purpose:
    `if` statement ↔️ Executes if true
    `else` statement ↔️ Executes if `if` is false
    `elif` statement ↔️ Chains multiple conditions
  • An `if` statement always requires an associated `else` statement.
    False
  • In an `elif` statement, the condition that chains multiple conditions must evaluate to true or false
  • What are the two primary types of loop structures in programming?
    `for` and `while`
  • A `for` loop is best used when the number of iterations is known.
  • Order the components of a `for` loop:
    1️⃣ Initialization
    2️⃣ Condition
    3️⃣ Increment
  • What does an `if` statement do?
    Executes code if true
  • An `else` statement executes when the `if` condition is false.
  • The `elif` statement is used to chain multiple conditions
  • What type of loop repeats for a fixed number of iterations?
    for loop
  • A `while` loop repeats as long as a condition remains true
  • Match the loop type with its use case:
    for loop ↔️ Fixed number of iterations
    while loop ↔️ Uncertain number of iterations
  • What is a definite loop?
    Fixed number of iterations
  • Indefinite loops typically use `while` loops.
  • Control structures govern the order in which instructions are executed in a program.
  • Order the three basic types of control structures:
    1️⃣ Sequential Execution
    2️⃣ Branching
    3️⃣ Loops
  • What is the execution order in sequential execution?
    Order of appearance
  • Branching uses `if` and `switch` statements to execute code based on conditions.
  • Loops repeat a code block until a specific condition is met.
  • What keywords are associated with loops?
    for, while, do-while
  • What is the outcome of the following code: x = 5; y = x + 10; print(y);</latex>
    15
  • Conditional statements use `if`, `else`, and `elif` keywords.
  • What is a `for` loop suitable for?
    Fixed number of iterations
  • Definite loops are typically implemented using for loops.
  • What type of loop is used when the number of iterations is uncertain?
    while loop