According to the Go Specification, break and continue are keywords.
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
break will break out of a loop. It's a way to stop looping.
continue will move on to the next iteration. Let's see it in action.
Aside dividing and remainders
example.go
package mainimport (string">"fmt")func main() {x := 83 / 40y := 83 % 40fmt.Println(x, y)}
note: % (modulo) is an Arithmetic operator that gives the remainder.
Back to continue in action. Let's say we want to iterate from 1 through to 100, and print out only the even numbers, we can use for, if, and continue
example.go
package mainimport (string">"fmt")func main() {x := 0for {x++string">"comment">// break out of the loop (stop the loop)string">"comment">// if x is greater than 100if x > 100 {break}string">"comment">// continue to the next iteration if thestring">"comment">// remainder of x divided by 2 is not 0string">"comment">// (if x is not even)if x%2 != 0 {continue}fmt.Println(x)}fmt.Println(string">"done.")}