Trace a two-level exit

A Bash warehouse simulation visits racks and numbered items in the listed order. Each inspection increments inspected; only items reaching the last update increment packed. Assume automatic exit on an unsuccessful command is disabled.


Determine the final inspection count and packed-item count. Enter both as exact integers with zero decimal places.


Shell
inspected=0
packed=0
for rack in 1 2 3; do
  for item in 1 2 3 4 5; do
    (( inspected += 1 ))
    if (( item == 2 )); then
      continue
    fi
    if (( rack == 2 && item == 4 )); then
      break 2
    fi
    (( packed += 1 ))
  done
done
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Bash Control Structures Questions: