Skip to content

Conditionals

TheRealMichaelWang edited this page Mar 30, 2021 · 3 revisions

Conditionals

Akin to C, FastCode doesn't implement a primitive boolean type, because they are redundant and unnecessary. Instead, conditional checks are performed by evaluating whether the conditional does not equal to 0 rather than checking whether a conditional equals to true.

Syntax

FastCode doesn't require expressions to be encapsulated with ( and ), but you can if you'd like.

So what does the true and false keywords actually do?

Like, the null keyword, they are substituted with 0 and 1 respectively during the tokenization process.

For example, if you try,

printl(true)
printl(false)

you'll get the output...

1
0

because there's no primitive boolean type.

Also, if you type

true = 1

or

false = 0

you'd get a syntax error because the lexer had already substituted them with their respective values. FastCode would think you typed...

1 = 1 //you can't set a variable with a value as an identifier

and

0 = 0

respectively. Same goes for the null keyword.

Tips and Tricks

Try using the decrement/increment operator as a conditional. That's a good trick.

The following example demonstrates how to count from 10 to 0.

i = 10
while i-- {
  printl(i)
}
//i is -1 at this point

The point is you can apply a larger range of operators to avoid doing mundane, repetitive, and often slower boolean manipulations. The previous example is actually faster because you don't have to evaluate i >= 0 then evaluate whether it's true.

Clone this wiki locally