006-005-007

Exit Nested Loops with Labeled break

Hard

Problem Description

Exit Nested Loops with Labeled break

In this problem, you will create a program that reads a 3x4 2D array and a target value from standard input, searches using a labeled break statement, and displays the found position to standard output.

Learning Objective: Understand how to exit multiple nested loops at once using labeled break

Overview

Create a program that searches for a specific value in a 2D array and exits all loops when found.

Specifications

  • Read 3 rows of 4 int values from standard input (4 space-separated integers per row)
  • Then read the target value to search for
  • Use labeled break to exit both loops when the target is found
  • Output the position if found, or "Not found" if not found

Input Format

row0_col0 row0_col1 row0_col2 row0_col3
row1_col0 row1_col1 row1_col2 row1_col3
row2_col0 row2_col1 row2_col2 row2_col3
target

Output Format

Found {target} at [{row}][{col}]

or

Not found

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up