PowerShell - Control FlowWhich of the following is the correct syntax for a foreach loop in PowerShell?Aforeach ($item in $list) { Write-Output $item }Bforeach $item in $list { Write-Output $item }Cforeach ($item : $list) { Write-Output $item }Dforeach ($item; $list) { Write-Output $item }Check Answer
Step-by-Step SolutionSolution:Step 1: Recall correct foreach syntaxPowerShell foreach loops use: foreach ($var in $collection) { ... }Step 2: Match options to syntaxOnly foreach ($item in $list) { Write-Output $item } uses the correct 'in' keyword and parentheses.Final Answer:foreach ($item in $list) { Write-Output $item } -> Option AQuick Check:Syntax uses 'in' keyword inside parentheses [OK]Quick Trick: Look for 'foreach ($var in $collection)' pattern [OK]Common Mistakes:Omitting parentheses around variable and collectionUsing ':' or ';' instead of 'in'Missing the 'in' keyword
Master "Control Flow" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Why cmdlets are the building blocks - Quiz 3easy Cmdlets and Pipeline - Get-Member for object inspection - Quiz 13medium Cmdlets and Pipeline - Where-Object for filtering - Quiz 12easy Cmdlets and Pipeline - Pipeline concept (|) - Quiz 3easy Control Flow - While and Do-While loops - Quiz 11easy Control Flow - For loop - Quiz 5medium Operators - Ternary operator (PowerShell 7+) - Quiz 10hard Operators - Why operators perform comparisons and logic - Quiz 15hard Operators - Arithmetic operators - Quiz 10hard PowerShell Basics and Environment - Command discovery (Get-Command) - Quiz 12easy