0
0
Azurecloud~10 mins

Scripting with variables and loops in Azure - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Scripting with variables and loops
Start Script
Set Variable
Check Loop Condition
Execute Loop Body
Update Variable
Back to Check Loop Condition
The script starts by setting a variable, then checks a loop condition. If true, it runs the loop body, updates the variable, and repeats until the condition is false.
Execution Sample
Azure
count=0
while [ $count -lt 3 ]; do
  echo "Count is $count"
  count=$((count + 1))
done
This script prints the count from 0 to 2 by increasing the variable in a loop.
Process Table
StepVariable 'count'Condition 'count < 3'ActionOutput
10TruePrint 'Count is 0'Count is 0
21TruePrint 'Count is 1'Count is 1
32TruePrint 'Count is 2'Count is 2
43FalseExit loop
💡 Loop ends because count reaches 3 and condition '3 < 3' is False
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
count01233
Key Moments - 2 Insights
Why does the loop stop when count is 3?
Because the condition 'count < 3' becomes False at step 4, so the loop exits as shown in the execution_table row 4.
What happens if we forget to update 'count' inside the loop?
The variable 'count' would stay the same, causing the condition to always be True and the loop to run forever, never reaching the exit shown in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of 'count' at step 2?
A1
B0
C2
D3
💡 Hint
Check the 'Variable count' column in execution_table row 2.
At which step does the loop condition become false?
AStep 3
BStep 4
CStep 2
DStep 1
💡 Hint
Look at the 'Condition' column in execution_table to find when it is False.
If we start 'count' at 1 instead of 0, how many times will the loop run?
A1 time
B3 times
C2 times
D4 times
💡 Hint
Refer to variable_tracker and execution_table logic for how count changes and loop condition.
Concept Snapshot
Scripting with variables and loops:
- Initialize a variable before the loop.
- Use a condition to control loop execution.
- Inside the loop, perform actions and update the variable.
- Loop stops when condition is false.
- Always update variables to avoid infinite loops.
Full Transcript
This visual execution shows a simple script using a variable and a loop. The variable 'count' starts at 0. The loop checks if 'count' is less than 3. If yes, it prints the count and increases it by 1. This repeats until 'count' reaches 3, then the loop stops. Key points include updating the variable inside the loop and understanding when the loop ends.