Complete the code to print numbers from 1 to 3 using a loop.
for ($i = 1; $i -le 3; $i[1]) { Write-Output $i }
The ++ operator increases the value of $i by 1 each loop, allowing the loop to progress from 1 to 3.
Complete the code to check if a number is positive and print a message.
if ($number [1] 0) { Write-Output 'Positive number' }
-lt which checks for less than, not greater than.-eq which checks for equality, not greater than.The operator -gt means 'greater than'. It checks if $number is greater than 0.
Fix the error in the loop condition to stop at 5.
while ($count [1] 5) { Write-Output $count; $count += 1 }
-le which includes 5 and may cause an extra loop.-gt or -ge which reverse the logic.The loop should continue while $count is less than 5, so -lt is the correct operator.
Fill both blanks to create a loop that prints even numbers from 2 to 10.
for ($num = 2; $num [1] 10; $num [2] 2) { Write-Output $num }
-lt which excludes 10 from the loop.-= which decreases the number and causes an infinite loop.The loop runs while $num is less than or equal to 10 (-le), and increases $num by 2 each time (+=).
Fill all three blanks to create a dictionary of words and their lengths for words longer than 3 letters.
$lengths = @{}; foreach ([3] in $words) { if ([3].Length -gt 3) { $lengths[[1]] = [2] } }The dictionary uses word as the key, word.Length as the value, and loops over word in $words. The condition checks if the length is greater than 3.