Gauntlet Documentation
  • 🏠Welcome
  • πŸ…Getting Started
    • 🧠Introduction To Gauntlet
  • ‼️Read before Proceeding
  • ⬇️Installation
  • πŸ‘¨β€πŸ’»VSCode Extension
  • πŸ“šBasics
    • πŸ’¨Running Gauntlet
    • πŸ“„File Setup & Hello World
  • πŸ” Scope Variables
  • πŸ–ΌοΈConstants
  • 🧩Functions
  • ↔️If Statements
  • πŸ”‘Ternary Operator
  • πŸ’ Switch-Case
  • πŸ“©Select-Case
  • ➰Loops
  • πŸ“Structs
  • 🧱Interfaces
  • πŸͺͺAliases
  • πŸ“ŽMethods
  • πŸ¦™Lambdas
  • πŸ•ΈοΈMiscellaneous
  • ⚑Advanced Features
    • πŸ”€When-Cases
    • 🚰Pipes
    • ⁉️Try-Statements
    • 🎭Force-Statements
    • 🌯Wrapper Types
Powered by GitBook
On this page
  • If-statement syntax
  • Working Example
Export as PDF

If Statements

If-statement syntax

if <expr> {
    <if statement body>
}
elif <expr> {
    <else if statement body>
}
else {
    <else statement body>
}

Working Example

package main

import "fmt" as fmt


fun Unit main() {
  let isInRelationship = false
  let isProgrammer = true
  if isProgrammer && !isInRelationship {
    fmt.println("Makes sense")
  }
  elif !isProgrammer && isInRelationship {
    fmt.println("Makes sense")
  }
  elif !isProgrammer && !isInRelationship {
    fmt.println("It's ok, it won't be hard for you to find a relationship")
  }
  else {
    fmt.println("Stop lying")
  }
}
package main

import fmt "fmt"

func main() {
	isInRelationship := false
	isProgrammer := true
	if isProgrammer && !isInRelationship {
		fmt.Println("Makes sense")
	} else if !isProgrammer && isInRelationship {
		fmt.Println("Makes sense")
	} else if !isProgrammer && !isInRelationship {
		fmt.Println("It's ok, it won't be hard for you to find a relationship")
	} else {
		fmt.Println("Stop lying")
	}
	// Eliminates any 'unused variable' errors
	_, _ = isInRelationship, isProgrammer

}
Makes sense
PreviousFunctionsNextTernary Operator

Last updated 8 days ago

↔️