Which type of statements run only under certain conditions?

Study for the CodeHS AP Computer Science Principles (CSP) Exam. Prepare with flashcards and multiple choice questions, each question comes with hints and explanations. Get ready for success!

Multiple Choice

Which type of statements run only under certain conditions?

Explanation:
Decisions in code are made with conditionals. These statements check a boolean condition and run their block only if that condition is true. If the condition isn’t met, the code inside the conditional doesn’t run (you may have an else branch that handles the other case). That behavior—executing only when a certain condition is satisfied—is what makes conditionals the correct answer. For example, a statement like if (score >= 60) then show "pass" runs only when the score is at least 60. Loops also depend on a condition, but their purpose is to repeat the same block of code while the condition stays true, not just to decide once whether to run. Boolean expressions by themselves are the true/false questions used to form these conditions, not blocks of code that execute on their own.

Decisions in code are made with conditionals. These statements check a boolean condition and run their block only if that condition is true. If the condition isn’t met, the code inside the conditional doesn’t run (you may have an else branch that handles the other case). That behavior—executing only when a certain condition is satisfied—is what makes conditionals the correct answer. For example, a statement like if (score >= 60) then show "pass" runs only when the score is at least 60.

Loops also depend on a condition, but their purpose is to repeat the same block of code while the condition stays true, not just to decide once whether to run. Boolean expressions by themselves are the true/false questions used to form these conditions, not blocks of code that execute on their own.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy