func switchStatementExamples() {
fmt.Println("******************* SWITCH-STATEMENT *******************")
bingo := 3
switch bingo {
case 1:
fmt.Println("it ain't 1")
case 2:
fmt.Println("it ain't 2")
case 3:
fmt.Println("it ain't 3")
fmt.Println("WAIT...; IT ISS !!!!")
}
bingo = 5
var userInput int
for {
fmt.Println("PLEASE PICK A NUMBER")
fmt.Scan(&userInput)
switch {
case userInput < 0:
fmt.Println("IT AIN'T EVEN NEGATIVE U FUCK\n\n")
case userInput > 10:
fmt.Println("OVER YO HEAD !?\n\n")
case userInput == bingo:
fmt.Println("Finally, ouff; now get the fuck out!!!\n\n")
break // return works but the code below is unreachable
default:
fmt.Println("It aint it, DUMASS\n\n")
}
}
fmt.Println("______________________________________________\n\n\n_____________________________________")
fmt.Println("what you experienced right now is the normal switch statement with values; but that's not it; we can also switch between value's TYPE!!!")
fmt.Println("______________________________________________\n\n\n_____________________________________")
}
#switch break ain't breaking
9 messages · Page 1 of 1 (latest)
you're breaking from the switch, not from the loop
You could use a label like:
loop:
for {
switch {
case true:
break loop
}
}
Or put a variable in the loop
how to break also in the loop, can't i break twice or tell it break from nested 2 or some
ohh i see
okaty
func switchStatementExamples() {
fmt.Println("******************* SWITCH-STATEMENT *******************")
bingo := 3
switch bingo {
case 1:
fmt.Println("it ain't 1")
case 2:
fmt.Println("it ain't 2")
case 3:
fmt.Println("it ain't 3")
fmt.Println("WAIT...; IT ISS !!!!")
}
bingo = 5
var userInput int
+nameTheLoopSomethingThatMakesMoreSense:
for {
fmt.Println("PLEASE PICK A NUMBER")
fmt.Scan(&userInput)
switch {
case userInput < 0:
fmt.Println("IT AIN'T EVEN NEGATIVE U FUCK\n\n")
case userInput > 10:
fmt.Println("OVER YO HEAD !?\n\n")
case userInput == bingo:
fmt.Println("Finally, ouff; now get the fuck out!!!\n\n")
- break // return works but the code below is unreachable
+ break nameTheLoopSomethingThatMakesMoreSense
default:
fmt.Println("It aint it, DUMASS\n\n")
}
}
fmt.Println("______________________________________________\n\n\n_____________________________________")
fmt.Println("what you experienced right now is the normal switch statement with values; but that's not it; we can also switch between value's TYPE!!!")
fmt.Println("______________________________________________\n\n\n_____________________________________")
}
@tribal rover @fresh chasm thanks
If your question has been solved, please close the thread with </solved:1022173889255706726>