Tutorial by Examples

A simple switch statement: switch a + b { case c: // do something case d: // do something else default: // do something entirely different } The above example is equivalent to: if a + b == c { // do something } else if a + b == d { // do something else } else { ...
A simple if statement: if a == b { // do something } Note that there are no parentheses surrounding the condition and that the opening curly brace { must be on the same line. The following will not compile: if a == b { // do something } An if statement making use of else: if...
A simple type switch: // assuming x is an expression of type interface{} switch t := x.(type) { case nil: // x is nil // t will be type interface{} case int: // underlying type of x is int // t will be int in this case as well case string: // underlying type of x is st...
A goto statement transfers control to the statement with the corresponding label within the same function. Executing the goto statement must not cause any variables to come into scope that were not already in scope at the point of the goto. for example see the standard library source code: https:/...
The break statement, on execution makes the current loop to force exit package main import "fmt" func main() { i:=0 for true { if i>2 { break } fmt.Println("Iteration : ",i) i++ } } The continue statement, on execution...

Page 1 of 1