A variable is a container that holds information or data which can be used and changed during the script execution.
Click to reveal answer
beginner
Why do we use loops in scripting?
Loops let us repeat a set of instructions multiple times without writing the same code again and again.
Click to reveal answer
beginner
In Azure scripting, what does a 'for' loop do?
A 'for' loop repeats a block of code a specific number of times, usually counting from a start number to an end number.
Click to reveal answer
intermediate
How can variables and loops work together in a script?
Variables can store changing values, and loops can use these variables to repeat actions with different data each time.
Click to reveal answer
intermediate
Give an example of a simple Azure CLI script using a variable and a loop.
Example: Setting a variable for a resource group name and using a loop to create multiple storage accounts with different names.
Click to reveal answer
What is the main purpose of a variable in a script?
ATo repeat code multiple times
BTo store data that can change
CTo stop the script
DTo display messages
✗ Incorrect
Variables store data that can be used and changed during the script.
Which loop type repeats code a fixed number of times?
AWhile loop
BSwitch case
CIf statement
DFor loop
✗ Incorrect
A 'for' loop repeats code a set number of times.
In Azure CLI scripting, how do you assign a value to a variable?
Aset name value
Bvar name = value
Cname=value
Dlet name = value
✗ Incorrect
In Azure CLI scripts, variables are assigned using 'name=value' without spaces.
What happens if you forget to update a variable inside a loop?
AThe loop will use the same value every time
BThe loop will not run
CThe loop will run forever
DThe script will crash
✗ Incorrect
If the variable is not updated, the loop uses the same value each time.
Which of these is a benefit of using loops in cloud scripts?
AAutomating repetitive tasks
BIncreasing script size
CSlowing down deployment
DManually repeating commands
✗ Incorrect
Loops help automate repetitive tasks, saving time and effort.
Explain how variables and loops can be used together in an Azure script to automate resource creation.
Think about creating multiple resources with different names using a loop and a variable.
You got /4 concepts.
Describe the steps to create a simple loop in Azure CLI scripting and how to use a variable inside it.
Focus on how the loop counts and how the variable changes each time.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using variables in Azure scripting?
easy
A. To store values that can be reused throughout the script
B. To create loops that repeat commands
C. To delete resources automatically
D. To connect to the internet
Solution
Step 1: Understand what variables do
Variables hold information like names or numbers that you want to use again without typing them multiple times.
Step 2: Identify the correct purpose in scripting
Variables help scripts remember values so you can use them repeatedly and easily change them if needed.
Final Answer:
To store values that can be reused throughout the script -> Option A
Quick Check:
Variables = reusable values [OK]
Hint: Variables hold values to reuse in scripts [OK]
Common Mistakes:
Confusing variables with loops
Thinking variables delete resources
Believing variables connect to internet
2. Which of the following is the correct way to declare a variable named count with value 5 in an Azure CLI script?
easy
A. var count = 5
B. let count = 5
C. set count=5
D. count=5
Solution
Step 1: Recall Azure CLI variable syntax
In Azure CLI scripts (bash style), variables are assigned without keywords using name=value format.
Step 2: Match the correct syntax
count=5 uses count=5, which is the correct bash style assignment.
Final Answer:
count=5 -> Option D
Quick Check:
Azure CLI variable = name=value [OK]
Hint: Use name=value to assign variables in Azure CLI [OK]
Common Mistakes:
Using 'var' or 'let' which are not bash syntax
Using 'set' which is Windows CMD syntax
Adding spaces around '=' which breaks assignment
3. What will be the output of this Azure CLI script snippet?
for i in 1 2 3; do
echo $((i * 2))
done
medium
A. 2 4 6
B. 0 1 2
C. 1 2 3
D. Syntax error
Solution
Step 1: Understand the loop iterations
The loop runs with i values 1, then 2, then 3.
Step 2: Calculate the expression inside echo
Each iteration prints i multiplied by 2: 1*2=2, 2*2=4, 3*2=6.
Final Answer:
2 4 6 -> Option A
Quick Check:
Loop * 2 = 2 4 6 [OK]
Hint: Multiply loop variable inside $(( )) for math [OK]
Common Mistakes:
Confusing echo $i with echo $((i * 2))
Expecting space-separated output on one line
Thinking syntax error due to missing semicolons
4. Identify the error in this Azure CLI script snippet:
for i in 1 2 3 do
echo $i
done
medium
A. echo command is incorrect
B. Variable $i is not defined
C. Missing semicolon or newline after for statement
D. done keyword is missing
Solution
Step 1: Check for correct for loop syntax
In bash scripts, the for loop header must end with a semicolon or a newline before the do keyword.
Step 2: Identify the missing semicolon or newline
The snippet has no semicolon or newline after for i in 1 2 3, causing syntax error.
Final Answer:
Missing semicolon or newline after for statement -> Option C
Quick Check:
For loop header needs semicolon/newline before do [OK]
Hint: Add semicolon or newline before do in for loops [OK]
Common Mistakes:
Forgetting semicolon after for statement
Assuming $i is undefined
Thinking echo syntax is wrong
5. You want to create 3 Azure resource groups named rg1, rg2, and rg3 using a script with a loop and a variable prefix rg. Which script snippet correctly achieves this?
hard
A. prefix=rg
for i in 1 2 3; do
az group create --name $prefix + $i --location eastus
done
B. prefix=rg
for i in 1 2 3; do
az group create --name "$prefix$i" --location eastus
done
C. prefix=rg
for i in 1 2 3; do
az group create --name prefix$i --location eastus
done
D. for i in 1 2 3; do
az group create --name "rg" + i --location eastus
done
Solution
Step 1: Understand variable concatenation in bash
To combine a variable and a number, use double quotes and place variables side by side like "$prefix$i".
Step 2: Check each option for correct syntax
prefix=rg
for i in 1 2 3; do
az group create --name "$prefix$i" --location eastus
done correctly uses "$prefix$i" to form names rg1, rg2, rg3. Others use invalid concatenation or miss quotes.
Final Answer:
prefix=rg
for i in 1 2 3; do
az group create --name "$prefix$i" --location eastus
done -> Option B
Quick Check:
Use "$prefix$i" to join strings in bash [OK]
Hint: Use "$prefix$i" to join variable and number in bash [OK]
Common Mistakes:
Using + for string concat in bash
Not quoting variable expansions
Writing variable names without $ sign
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.