Skip to content

GoCelesteAI/go_control_flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Control Flow: if/else

Code examples from Go Tutorial for Beginners #6 - Control Flow: if/else

Contents

  • basic_if.go - Basic if statements
  • if_else.go - if-else and else-if chains
  • short_statement.go - Short statement syntax (declare variables in if)
  • logical_operators.go - Logical operators (&&, ||, !) and comparison operators

Running the Examples

go run basic_if.go
go run if_else.go
go run short_statement.go
go run logical_operators.go

Key Concepts

Basic if Statement

if age >= 18 {
    fmt.Println("You are an adult")
}

if-else Chain

if score >= 90 {
    fmt.Println("Grade: A")
} else if score >= 80 {
    fmt.Println("Grade: B")
} else {
    fmt.Println("Grade: F")
}

Short Statement Syntax

if num := 10; num%2 == 0 {
    fmt.Println(num, "is even")
}

Logical Operators

if hasLicense && hasCar {
    fmt.Println("You can drive!")
}

Watch the Tutorial

Go Tutorial for Beginners #6 - Control Flow: if/else

License

MIT

About

Go Tutorial #6 - Control Flow: if/else examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages