0
0
Goprogramming~15 mins

Continue statement in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Continue Statement in Go
๐Ÿ“– Scenario: Imagine you are checking a list of daily temperatures to find which days were warm enough to go outside. You want to skip cold days and only note the warm days.
๐ŸŽฏ Goal: You will write a Go program that uses the continue statement inside a loop to skip cold days and print only the warm days.
๐Ÿ“‹ What You'll Learn
Create a slice of integers called temperatures with the exact values: 15, 22, 8, 19, 30, 12
Create an integer variable called warmThreshold and set it to 20
Use a for loop with the variable temp to go through temperatures
Inside the loop, use continue to skip temperatures less than warmThreshold
Print each warm temperature using fmt.Println(temp)
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Filtering data based on conditions is common in many programs, like showing only important messages or selecting items that meet certain criteria.
๐Ÿ’ผ Career
Understanding how to use loops and control statements like <code>continue</code> helps you write efficient code that processes data correctly, a skill needed in software development.
Progress0 / 4 steps
1
Create the temperatures slice
Create a slice of integers called temperatures with these exact values: 15, 22, 8, 19, 30, 12
Go
Need a hint?

Use temperatures := []int{...} to create the slice with the exact numbers.

2
Add the warmThreshold variable
Create an integer variable called warmThreshold and set it to 20
Go
Need a hint?

Use warmThreshold := 20 to create the variable.

3
Use a for loop with continue to skip cold days
Use a for loop with the variable temp to go through temperatures. Inside the loop, use continue to skip temperatures less than warmThreshold
Go
Need a hint?

Use for _, temp := range temperatures to loop. Use if temp < warmThreshold { continue } to skip cold days.

4
Print the warm temperatures
Inside the loop, after the continue statement, print each warm temperature using fmt.Println(temp)
Go
Need a hint?

Use fmt.Println(temp) to print the warm temperatures inside the loop.