IF Statement

This lesson explains how to use if statements in Go using examples

We'll cover the following

Comparison With Other Languages

The if statement looks as it does in C or Java, except that the ( ) are gone and the { } are required. Like for, the if statement can start with a short statement to execute before the condition. Variables declared by the statement are only in scope until the end of the if. Variables declared inside an if short statement are also available inside any of the else blocks.

  • Example of an if statement:

Get hands-on with 1200+ tech skills courses.