Not every building has an infinit amount of floors. Our simulated building is supposed to have 10. So it makes no sense to move to a floor higher than 10. To encode that kind of behavior we need a new language feature. The if-statement. # Knowledge The if statement allows you to check, if a certain condition is met and only execute parts of your code if it is. if(condition) { // gets executed, if condition is true } else { // gets executed, if condition is false } The else part is optional. To formulate a condition you need new operators.
Operator | Meaning |
---|---|
== | True, when both sides are equal |
!= | True, when both side are not equal |
< | True, when left is less than right |
> | True, when left is bigger than right |
<= | True, when left is less than or equal to the right |
>= | True, when left is bigger or equal to the right |
&& | Only true, if both conditions are true |
|| | True, when one condition is true |
! | negates the condition |