0
0
Goprogramming~30 mins

Labelled break and continue in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Labelled break and continue in Go
๐Ÿ“– Scenario: Imagine you are managing a small factory with multiple production lines. Each line produces different products, and you want to check the quality of each product. If a product fails quality check, you want to stop checking that line and move to the next one. Also, if a product is perfect, you want to skip some extra checks and continue with the next product.
๐ŸŽฏ Goal: You will write a Go program that uses labelled break and continue statements to control loops over production lines and products. This will help you understand how to jump out of or skip iterations in nested loops.
๐Ÿ“‹ What You'll Learn
Create a nested loop to iterate over production lines and products
Use a labelled break to exit the outer loop when a product fails quality
Use a labelled continue to skip extra checks for perfect products
Print messages showing the flow of checks and loop control
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
In factories or software testing, sometimes you need to stop checking a group when a problem is found or skip unnecessary steps for perfect items.
๐Ÿ’ผ Career
Understanding labelled break and continue helps in writing clear and efficient code for nested loops, common in data processing, simulations, and automation tasks.
Progress0 / 4 steps
1
Create production lines and products
Create a variable called lines which is a slice of slices of strings. It should have exactly two production lines: the first line has products "A1", "A2", and the second line has products "B1", "B2".
Go
Need a hint?

Use a slice of slices of strings to represent lines and their products.

2
Add quality status for products
Create a map called quality with string keys and string values. It should have these entries: "A1": "perfect", "A2": "fail", "B1": "ok", "B2": "perfect".
Go
Need a hint?

Use a map to store the quality status of each product.

3
Use labelled break and continue in nested loops
Write nested for loops to iterate over lines and their products. Use a label LineCheck for the outer loop. Inside the inner loop, if the product's quality is "fail", use break LineCheck to stop checking all lines. If the quality is "perfect", print "Skipping extra checks for [product]" and use continue to skip to the next product. Otherwise, print "Checking product [product]".
Go
Need a hint?

Use a label before the outer loop and refer to it in the break statement. Use continue inside the inner loop to skip to the next product.

4
Print the final output
Add a print statement after the loops that prints exactly "Quality check complete." to show the process ended.
Go
Need a hint?

Use fmt.Println("Quality check complete.") after the loops.