In below piece of code, I am unable to understand why the break
statement in default
is not sufficient to end infinite loop. PlayGroundLink
package main
import "fmt"
func main() {
for { //infinite loop
fmt.Print("Enter Choice")
userChoice := 3 //Intenssionaly given value here for testing
switch userChoice {
case 1:
fmt.Println("Enter Radios of Circle:")
case 2:
fmt.Println("Enter Radios of Circle:")
default:
fmt.Println("\nExiting...")
break // this break is executing , but why it is not coming out of infinte 'for' loop ?
}
}
}
OutPut of above Code (Not Ending .. keep on going )
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...
Enter Choice
Exiting...