Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Conditionals

Guillem Jara edited this page Oct 24, 2021 · 3 revisions

Let's take a closer look at what we saw before about syntax.

First we'll talk about the conditional, '<@VARIABLE | STRING> OPERATOR <@VARIABLE | STRING> [|| | && ANOTHER_CONDITIONAL ...]. If we simplify this we can see that's just a regular binary conditional and anyone that has coded a bit in their life won't have problems.

Let's create a basic conditional like that: @name == awesome_file. we'll discuss later what means the @, now let's focus on the conditional. We can split it in 3 parts:

  • @name: First candidate, the operator will evaluate it with the second candidate
  • ==: Operator, determines how to evaluate the conditional.
  • awesome_file: second candidate, evaluated against the first candidate by the operator.

Now let's talk about precedence, it's like chaining conditionals, and again, anyone that has coded a bit will be used to it. There are 2 types of precedence:

  • &&: Will only yield true if the conditionals between it are both true.
  • ||: Will yield true if any of the conditional between it are so.

Now we can make a "complex" conditional: @name == awesome_file && @elf != true. It will be true if @name is exactly awesome_file, and @elf evaluates to false.

We've only seen 2 operators, here is the list with all of them:

  • ==: true if the first value matches the second
  • !=: true if the first value doesn't match the second
  • >: true if the first value is greater than the second
  • >=: true if the first value is equal or greater than the second
  • <: true if the first value is less than the second
  • <=: true if the first value is equal or less than the second
  • ~=: true if a value matches the regular expression provided in the other value
  • ~!: true if a value doesn't match the regular expression provided in the other value
Clone this wiki locally