Which control structure executes a block of code while a condition is true?

Study for the Internet of Things (IOT102) Test. Access comprehensive flashcards and multiple choice questions, each with hints and explanations. Get prepared for your exam!

Multiple Choice

Which control structure executes a block of code while a condition is true?

Explanation:
The idea is to repeat a block of code as long as a condition stays true. A while loop checks the condition first, and if it’s true it runs the block, then checks again, continuing this way until the condition becomes false. That direct behavior—executing while the condition holds—matches the description perfectly. By contrast, a do-while loop runs the block first and then tests the condition, so it can run once even if the condition is false initially. A for loop is mainly a compact form for counting with initialization and an update step, though it can emulate a while loop, it’s not defined by the “execute while true” rule. An if-else simply chooses a single path once and doesn’t repeat. For example: while (x < 10) { /* do work */ x++; }

The idea is to repeat a block of code as long as a condition stays true. A while loop checks the condition first, and if it’s true it runs the block, then checks again, continuing this way until the condition becomes false. That direct behavior—executing while the condition holds—matches the description perfectly. By contrast, a do-while loop runs the block first and then tests the condition, so it can run once even if the condition is false initially. A for loop is mainly a compact form for counting with initialization and an update step, though it can emulate a while loop, it’s not defined by the “execute while true” rule. An if-else simply chooses a single path once and doesn’t repeat. For example: while (x < 10) { /* do work */ x++; }

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy