Flow control
Flow control is referred as the ability to decide which portion of code or how many times you execute some code on a condition. In Go, it is implemented using familiar imperative clauses like if, else, switch and for. The syntax is easy to grasp. Let´s review major flow control statements in Go.
The if... else statement
Go language, like most programming languages, has if…else
conditional statement for flow control. The Syntax is similar to other languages but you don't need to encapsulate the condition between parenthesis:
ten := 10 if ten == 20 { println("This shouldn't be printed as 10 isn't equal to 20") } else { println("Ten is not equals to 20"); }
The else...if
condition works in a similar fashion, you don't need parentheses either and they are declared as programmer would expect:
if "a" == "b" || 10 == 10 || true == false { println("10 is equal to 10") } else if 11 == 11 &&"go" == "go" { println...