In Go, there are two keywords for conditional statements—if, and switch. Let's take a practical look at each one of them.
Conditional statements and loops
The if statement
The if statement looks like this:
if <condition>{
}
So, let's assume we want to compare whether a value, x, is equal to 10. Here is what the syntax would look like:
if x == 10{
}
In Go, you can also execute some initialization in your if statement. Here is what this syntax would look like:
if x := getX(); x == 5{
}
Like other programming languages, an if statement is never complete without an else clause. Here is what an if else looks like in Go:
if x==5{
}else{
}
How about an else clause with a condition?
if x == 5{
}else if x >10{
}...