From the course: Learning Go (2021)
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Program conditional logic - Go Tutorial
From the course: Learning Go (2021)
Program conditional logic
- (Narrator) I've been using simple conditional logic throughout this course. But it's worth reviewing how Go's syntax for the if statement differs from other C style languages. The if statement in Go looks just like C or Java for the most part, but it doesn't require parentheses around the Boolean condition. I'll start by creating a variable integer that I'll name the answer and I'll give it a value of 42. Next, I need a string that I'll use as a result message. I'll declare it here but I'm not going to assign an initial value. I'll just say, it's going to be a string. Now, I'll add an if statement I'll use this Boolean condition the answer less than zero. Then I'll add braces, and within the braces, I'll set the value of result to a string of less than zero. Now, I can optionally add one or more elseif statements. I'll start with elseif and then I need another Boolean condition. This time, it will be the…