If Statement

The basic conditional

Quick Recap

Else statements work but there is a compiler bug that doesn't generate bytecode for the else statement, only the content of the else statement is generated. Therefore, the else statement will be executed even if the condition is true.

For the purpose of this tutorial and for ease of learning, the else statement has been omitted.

In the previous page, we learnt about the ranged for loop syntax of Cylvre and how it makes it unique and easy to learn, now we come to the topic of conditional statements, which makes a language (along with loops) Turing complete.

This is where Cylvre starts being slightly different. Built for simplicity, Cylvre has revamped the structure of the entire if statement, making it extremely easy to use and extremely concise too. Given below is a basic program in Cylvre that checks the divisibility of a number by 5.

func main(){
    x : 10;
    x = 10 ? println("is ten");
}

The if statement starts with the question, that is, the condition. The condition in the above program is x = 10. The if statement is then initialized by the question mark '?', just like the way we ask questions. If the condition is true, which it is in this case, the statement is executed or if the condition is false, the statement is skipped.

Last updated