Question 7
Domain 1: Developing Code for Data Processing using Python and SQLA data engineer is designing a pipeline component in Lakeflow Declarative Pipelines and needs the component to branch between two actions depending on whether a condition is met, and in another step repeat an action for each item in a collection. Which set of control flow operators should be used?
Correct answer: B
Explanation
Use if/else to choose between alternative actions based on a condition, and use foreach to repeat an action across items in a collection. — official.txt
Why each option is right or wrong
A. Use foreach for conditional branching and if/else for iterating through each item.
if/else handles conditional branching, while foreach iterates over items in a collection.
B. Use if/else for conditional branching and foreach for iterating through each item.
The source material identifies if/else and foreach as control flow operators. In this scenario, branching on whether a condition is met aligns with if/else, and repeating an action for each item in a collection aligns with foreach.
C. Use if/else for iterating through each item and use foreach only when no condition is involved.
foreach is used to repeat an action for each item; if/else is used to evaluate conditions.
D. Use only if/else for both the condition check and the repeated action across the collection.
foreach is the operator used for repeating actions across items in a collection.