Interview Prep/Shell Scripting/Arrays, conditionals and loops

How do you exit a loop early from inside a nested loop or a pipeline?

IntermediateConceptArrays, conditionals and loops
Answer

break N and continue N take the number of enclosing loops to affect:

for region in ap-south-1 us-east-1; do
  for az in a b c; do
    if az_unavailable "$region$az"; then continue 2; fi   # next region
    deploy "$region$az" || break 2                         # stop everything
  done
done

Inside cmd | while ..., break only leaves the subshell's loop; exit exits only the subshell. Use process substitution if you need to stop the whole script from inside the loop.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops