Julian Wiley

Flow Control

<!-- Condition -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Condition">}}

if day == "sunday" || day == "saturday" {
  rest()
} else if day == "monday" && isTired() {
  groan()
} else {
  work()
}
if _, err := doThing(); err != nil {
  fmt.Println("Uh oh")

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Switch -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Switch" >}}

switch day {
  case "sunday":
    // cases don't "fall through" by default!
    fallthrough

  case "saturday":
    rest()

  default:
    work()
}

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Loop -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Loop" >}}

for count := 0; count <= 10; count++ {
  fmt.Println("My counter is at", count)
}
entry := []string{"Jack","John","Jones"}
for i, val := range entry {
  fmt.Printf("At position %d, the character %s is present\n", i, val)
n := 0
x := 42
for n != x {
  n := guess()
}

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}