Bird
0
0

Why does a PowerShell function sometimes return multiple values even if it uses a return statement?

hard📝 Conceptual Q10 of 15
PowerShell - Functions
Why does a PowerShell function sometimes return multiple values even if it uses a return statement?
ABecause return only exits loops, not functions
BBecause return can only return one value at a time
CBecause PowerShell outputs all pipeline results before return exits
DBecause return converts all outputs to strings
Step-by-Step Solution
Solution:
  1. Step 1: Understand PowerShell output behavior

    PowerShell outputs any objects sent to the pipeline before the return statement executes.
  2. Step 2: Analyze why multiple outputs occur

    Commands before return output their results, so function can output multiple values even with return.
  3. Final Answer:

    Because PowerShell outputs all pipeline results before return exits -> Option C
  4. Quick Check:

    Pipeline outputs before return cause multiple values [OK]
Quick Trick: Pipeline outputs before return cause multiple outputs [OK]
Common Mistakes:
  • Thinking return only exits loops
  • Believing return limits output to one value always
  • Assuming return converts outputs to strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes