Terms

Terms

> LeekScript Tutorial

Good ! It's time to add conditions to your programs!

For now, your code still does the same thing. The conditions will remedy this.

Conditions are the first "control structure" we're going to talk about. These allow you to make your code more flexible, to ensure that it adapts to the context.

So far, you've seen that your code runs linearly, one statement at a time. Now, we are going to see how to execute or not execute code according to a condition.

Comparison operators

But before coming to the conditions, we must first return to the operators. We have mainly talked about the operators allowing calculations to be made, and to tackle the conditions, we will have to see those which allow comparisons to be made.

These operators are a little different from those we have already seen. For example, you saw that in LeekScript, the expression "4 + 6" results in 10. The result is an integer, a number. It is a mathematical expression expressing a calculation.

Comparison operators will allow you to write mathematical expressions that will express a relationship. If we write the expression "2 ", i.e. "Strictly less than" and "Strictly greater than". (If needed, the key for these symbols is to the left of the "W", one is done with the SHIFT key pressed, the other without)

In short, these operators make it possible to test the order relation between two elements. For example :

var result = a b;

If the value of "a" is strictly greater than that of "b", the result will be true, which will be assigned to the "result" variable. If it's the other way around, it will be false.

We are talking here about "strict" relationships. If a and b have the same value, the result will be false; since neither is smaller or larger than the other.

Mixed Relational Operators

And now the non-strict version of the relational operators.

Thus, for the greater than or equal operator, it suffices to mix the equality and relation operators. We get the operator ">="! The symbol