Control Structures: Study Flashcards (Hover to Reveal)

What are **Control Structures** in programming?
They are instructions that control the **flow or order** in which code is executed, allowing for decisions and repetition.
What are the **three main categories** of Control Structures?
1. **Loops** (Repetition)
2. **Branches** (Decisions)
3. **Function/Procedure Calls**
What is the **primary purpose** of a Loop?
To **automate repetitive tasks** and avoid writing the same code multiple times.
Which type of loop runs a **specific number of times**?
A **'For' loop**.
Which type of loop continues **as long as a certain condition is true**?
A **'While' loop**.
What is the **'Break' command** used for inside a loop?
To **immediately stop or exit the loop**, even if the loop's condition is still true.
What do **'Branches'** allow your code to do?
They allow the code to **make decisions** and choose which block of code to run based on a condition.
What is the **most fundamental branching statement**?
The **'IF' statement**.
When does the code inside an **'IF' statement** run?
It runs only when the **condition** being checked is **'true'**.
What is the purpose of the **'ELSE' statement**?
To provide a block of code that runs if the **'IF' condition is 'false'**.
What does an **'ELSE IF'** (or **'ELIF'**) statement allow you to do?
It allows you to check for **multiple different conditions** in sequence, one after another.
What is the main purpose of using **Functions**?
To group a **reusable block of code** that performs a specific task, making the main program cleaner.
What does it mean to **'define'** a function?
It means to **create the function** and write the code that it will execute.
In Python, which keyword is used to start **defining a function**?
The **'def'** keyword.
What does it mean to **'call'** a function?
It means to tell the program to **run or execute** the code inside that function.
What are **'arguments'** in a function?
They are the **input values or data** that you pass into the function for it to work with.
What is the main difference between a **Function** and a **Procedure**?
A **Function returns a value** after it runs, while a **Procedure does not return a value**.
If a loop's condition never becomes false, what is this called?
An **infinite loop**, which can cause the program to crash.
Which control structure would you use to print numbers **1 to 100**?
A **'For' loop**, because you know exactly how many times you need to repeat the action.
Which control structure would you use to keep a game running **until the player quits**?
A **'While' loop**, because it continues as long as a condition (e.g., 'game_is_running') is true.
What is the purpose of **'declaring arguments'**?
To **define what kind of input** a function needs to do its job.
Can you have an **'ELSE' statement** without an **'IF' statement**?
**No**, an 'ELSE' statement must always follow an 'IF' or 'ELSE IF' to handle the 'false' condition.
What is another name for a **'Branch'**?
A **decision** or **conditional statement**.
What is the term for **repeating a set of instructions**?
**Iteration** or **Looping**.
In a program that checks age, which branch handles an input of '18' if the check is **'IF age is less than 18'**?
The **'ELSE' branch**, because the condition ('18 is less than 18') is false.