0
0
PowerShellscripting~5 mins

Range operator (..) in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the range operator (..) do in PowerShell?
It creates an array of numbers from a start value to an end value, including both.
Click to reveal answer
beginner
How do you create a sequence of numbers from 1 to 5 using the range operator?
Use 1..5 which produces the array 1, 2, 3, 4, 5.
Click to reveal answer
intermediate
What happens if the start number is greater than the end number in a range expression like 5..1?
PowerShell creates a descending array: 5, 4, 3, 2, 1.
Click to reveal answer
beginner
Can the range operator be used with variables? Give an example.
Yes. For example, $start=3; $end=7; $start..$end creates 3, 4, 5, 6, 7.
Click to reveal answer
beginner
Is the range operator inclusive or exclusive of the end values?
It is inclusive, meaning both the start and end numbers are included in the output array.
Click to reveal answer
What does the PowerShell expression 2..6 produce?
A[2,3,4,5]
B[6,5,4,3,2]
C[3,4,5,6]
D[2,3,4,5,6]
What is the output of 10..7 in PowerShell?
A[10,9,8,7]
BError
C[7,8,9,10]
D[10,7]
Which of these is a valid way to use the range operator with variables?
Arange($a,$b)
B$a..$b
C$a to $b
D[$a,$b]
If you want numbers from 1 to 10, which is the correct PowerShell syntax?
Arange(1,10)
B1-10
C1..10
D1 to 10
Does the range operator include the last number in the sequence?
AYes, it includes the last number.
BNo, it excludes the last number.
COnly if the start is less than the end.
DOnly if the start is greater than the end.
Explain how the range operator (..) works in PowerShell and give an example.
Think about how you count numbers from one to another.
You got /3 concepts.
    What happens if the first number is bigger than the second in a range expression? Describe the output.
    Consider counting backwards.
    You got /3 concepts.