Question 8
Domain 1: Developing Code for Data Processing using Python and SQLYou are designing a Databricks pipeline component that must process a list of input items one at a time using the same logic for each item. Which control flow operator is the best choice for this requirement?
Correct answer: B
Explanation
Use a foreach operator when the same processing steps must be applied repeatedly to each item in a collection, and use if/else when execution should branch based on a condition. — official.txt
Why each option is right or wrong
A. Use an if/else operator to repeat the same processing for every item in the list.
If/else selects between branches based on a condition rather than iterating through a collection.
B. Use a foreach operator to apply the processing logic to each item in the list.
The requirement is to process a list of input items one at a time using the same logic. The source material identifies foreach as a control flow operator for this kind of repeated per-item execution in a pipeline component.
C. Use an if/else operator to evaluate all items together as a single branch decision.
Foreach handles repeated execution across items; if/else is for condition-based branching.
D. Use a foreach operator only when the pipeline must choose between two conditional paths.
If/else is used to choose between alternative paths based on a condition.