Complete the code to loop through each item in the array and print it.
foreach ($item [1] $array) { Write-Output $item }The keyword in is used in PowerShell to loop through each element in a collection.
Complete the code to loop through numbers 1 to 5 and print each number.
foreach ($num [1] 1..5) { Write-Output $num }
Use in to loop through a range of numbers in PowerShell.
Fix the error in the loop to correctly print each name in the list.
$names = @('Anna', 'Bob', 'Cara') foreach ($name [1] $names) { Write-Output $name }
The correct keyword to iterate over a collection in PowerShell is in.
Fill both blanks to create a loop that prints only even numbers from 1 to 10.
foreach ($num [1] 1..10) { if ($num [2] 2 -eq 0) { Write-Output $num } }
Use in to loop through the numbers and % (modulus) to check if the number is even.
Fill all three blanks to create a dictionary of word lengths for words longer than 3 characters.
$words = @('cat', 'house', 'tree', 'a', 'dog') $lengths = @{} foreach ($word [1] $words) { if ($word.Length [2] 3) { $lengths[[3]] = $word.Length } } $lengths
Use in to loop through words, > to check length greater than 3, and $word as the dictionary key.