Recall & Review
beginner
What is a
while loop in bash scripting?A
while loop repeats a block of commands as long as a given condition is true. It helps automate repeated tasks until the condition changes.Click to reveal answer
beginner
How do you write a basic
while loop in bash?Use this structure:<br>
while [ condition ]; do<br> commands<br>done<br>The commands run repeatedly while the condition is true.
Click to reveal answer
intermediate
What happens if the
while loop condition is never false?The loop runs forever, creating an infinite loop. You must include a way to stop it, like changing a variable inside the loop or using
break.Click to reveal answer
intermediate
How can you stop a
while loop early in bash?Use the
break command inside the loop to exit immediately, even if the condition is still true.Click to reveal answer
beginner
Why is it important to update variables inside a
while loop?Updating variables changes the condition over time. Without this, the loop might never end because the condition stays true forever.
Click to reveal answer
What keyword starts a loop that runs while a condition is true in bash?
✗ Incorrect
The
while keyword starts a loop that runs as long as the condition is true.Which command stops a
while loop immediately inside the loop?✗ Incorrect
The
break command exits the loop immediately.What happens if the condition in a
while loop never becomes false?✗ Incorrect
If the condition never becomes false, the loop runs forever, causing an infinite loop.
Which symbol is used to test conditions inside a
while loop in bash?✗ Incorrect
Square brackets
[] are used to test conditions in bash.How do you write a
while loop that counts from 1 to 5 in bash?✗ Incorrect
Option C shows the correct bash syntax for a
while loop counting from 1 to 5.Explain how a
while loop works in bash and why updating variables inside it is important.Think about how the loop knows when to stop.
You got /4 concepts.
Describe how to safely stop a
while loop before its condition becomes false.Consider commands that control loop flow.
You got /4 concepts.