PowerShell - Control FlowHow can you use a switch statement to run the same code for multiple matching values, like 'cat' and 'dog'?Aswitch ($animal) { 'cat' { 'Pet' } 'dog' { 'Pet' } default { 'Other' } }Bswitch ($animal) { 'cat','dog' { 'Pet' } default { 'Other' } }Cswitch ($animal) { 'cat' -or 'dog' { 'Pet' } default { 'Other' } }Dswitch ($animal) { case 'cat','dog' { 'Pet' } default { 'Other' } }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand multiple matches in switchPowerShell allows comma-separated values in a single case to match multiple inputs.Step 2: Check options for correct syntaxswitch ($animal) { 'cat','dog' { 'Pet' } default { 'Other' } } correctly uses 'cat','dog' in one case. Others use invalid syntax or keywords.Final Answer:switch ($animal) { 'cat','dog' { 'Pet' } default { 'Other' } } -> Option BQuick Check:Comma separates multiple matches in one case [OK]Quick Trick: Use commas to group multiple values in one case [OK]Common Mistakes:Using -or inside caseAdding 'case' keywordTrying to use logical operators inside switch
Master "Control Flow" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Get-Member for object inspection - Quiz 5medium Operators - Comparison operators (-eq, -ne, -gt, -lt) - Quiz 13medium Operators - String comparison (-like, -match) - Quiz 15hard PowerShell Basics and Environment - PowerShell console and ISE - Quiz 1easy PowerShell Basics and Environment - Command discovery (Get-Command) - Quiz 8hard PowerShell Basics and Environment - Command discovery (Get-Command) - Quiz 12easy String Operations - String methods (.Split, .Replace, .Trim) - Quiz 5medium String Operations - Why string manipulation is frequent - Quiz 12easy Variables and Data Types - Why variables store data - Quiz 10hard Variables and Data Types - String type and interpolation - Quiz 3easy