🐕
Corgi
  • 🐕About Corgi
  • 🎓Learning Corgi
    • 📂File Structure
    • 🎉Getting Started
    • 🔟Code
    • 📄Arrow Blocks
    • 🪄If and Switch
    • ✏️Interpolation
    • 🔁For
    • 🤝Attributes
    • 🎭Expressions
    • 👮Security and Escaping
    • 💉Nonce Injection
    • ➡️Block Expansions
    • ➕Mixins
    • 📚Libraries
    • ✨The Standard Library
    • 💬Comments
    • ⛓️Filters
    • 🖨️Include
    • 👪Inheritance (Extending)
    • ⚡Breaking Changes
Powered by GitBook
On this page
  • If
  • Switch

Was this helpful?

  1. Learning Corgi

If and Switch

Corgi allows you to use both ifs and switches, without having to use - code.

If

Just write an if as you otherwise would in Go, minus the trailing {.

import 
  "strings"
  "math/rand"



func F()

- s := "fOo"

if s == "foo"
  p s is 'foo'!
else if strings.EqualFold(s, "foo")
  p s is almost 'foo'!
  
if r := rand.Intn(11); r >= 5
  p I forsee great fortune for you today.
import (
    "strings"
    "math/rand"
    _io "io"
)

func F(_w _io.Writer) error {

    s := "foo"
    
    if s == "foo" {
        // p s is 'foo'!
    } else if strings.EqualFold(s, "foo") {
        // p s is almost 'foo'!
    }
    if r := rand.Intn(11); r >= 5 {
        // p I forsee great fortune for you today.
    }
}

Switch

Similarly, you can write a switch just like in go, just without { and :.

- s := "abc"
p
  switch s
    case "foo", "bar"
      > foo, bar
    case "abc", "def", "jkl"
      > alphabet

s := "abc"
// <p>
  switch s {
  case "foo", "bar":
    // > foo, bar
  case "abc", "def", "jkl":
    // > alphabet
  }
// </p>
PreviousArrow BlocksNextInterpolation

Last updated 1 year ago

Was this helpful?

🎓
🪄