0
0
Bash Scriptingscripting~5 mins

until loop in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does an until loop do in Bash scripting?
An until loop runs the commands inside it repeatedly until the given condition becomes true. It keeps running while the condition is false.
Click to reveal answer
beginner
How is an until loop different from a while loop?
A while loop runs while the condition is true. An until loop runs while the condition is false, stopping when it becomes true.
Click to reveal answer
beginner
Write the basic syntax of an until loop in Bash.
until [ condition ] do commands done
Click to reveal answer
beginner
What will this script print?
count=1
until [ $count -gt 3 ]
do
  echo $count
  ((count++))
done
It will print: 1 2 3 The loop runs until count is greater than 3, so it prints 1, 2, and 3.
Click to reveal answer
intermediate
Why might you choose an until loop instead of a while loop?
You use until when you want to repeat commands until a condition becomes true. It can make your code easier to read if you think in terms of "keep going until this happens."
Click to reveal answer
What condition causes an until loop to stop running?
AWhen the condition becomes true
BWhen the condition becomes false
CAfter one iteration
DNever stops
Which of these is the correct syntax to start an until loop?
Awhile [ condition ]; do
Buntil [ condition ]; do
Cfor i in [ condition ]; do
Dif [ condition ]; then
What will this script print?
count=5
until [ $count -lt 3 ]
do
  echo $count
  ((count--))
done
ANothing
B3 4 5
C1 2 3
D5 4 3
Which loop runs while the condition is true?
Auntil loop
Bnone
Cwhile loop
Dboth until and while
What happens if the condition in an until loop is true at the start?
AThe loop does not run at all
BThe loop runs forever
CThe loop runs once
DThe loop runs twice
Explain how an until loop works in Bash and give a simple example.
Think about repeating something until a condition becomes true.
You got /4 concepts.
    Compare and contrast until and while loops in Bash scripting.
    Focus on when each loop continues and stops.
    You got /4 concepts.