|
| 1 | +#CONDITIONAL EXPRESSIONS BASICS by DevKev for version 1.9.10# |
| 2 | + |
| 3 | +#To create if statements, you can use the "if [boolean] [block]" command |
| 4 | +Remember, unlike java or similar languages, you still need to use ";" to terminate a command even if it ends with a "}"# |
| 5 | + variable = $true; |
| 6 | + if $variable { |
| 7 | + println "The variable is true!"; |
| 8 | + }; |
| 9 | + |
| 10 | + |
| 11 | +#If statements work like in most programming languages:# |
| 12 | + if $false { |
| 13 | + #...# |
| 14 | + } else { |
| 15 | + #...# |
| 16 | + }; |
| 17 | + |
| 18 | + |
| 19 | +#"elseif" is also possible# |
| 20 | + if $false { |
| 21 | + #...# |
| 22 | + } elseif $true { |
| 23 | + #...# |
| 24 | + } else { |
| 25 | + #...# |
| 26 | + }; |
| 27 | + |
| 28 | + |
| 29 | +#You can also use the command [boolean] ? [???] [???]" as ternary expression |
| 30 | +If the condition is true, the 3rd argument is returned, otherwise the 4th# |
| 31 | + condition = $true; |
| 32 | + println ($condition ? "Condition is true" "Condition is false"); |
| 33 | + |
| 34 | + |
| 35 | +#To compare two variables you can use the following commands with the two example Variables $var0 and $var1: |
| 36 | + "$var0 == $var1" <- Returns $true, if $var0's toString() equals $var1 |
| 37 | + "$var0 != $var1" <- Returns $true, if $var0's toString() does not equal $var1 |
| 38 | + "$var0 lt $var1" <- Returns $true, if $var0 is less than $var1 (Works only with numbers) |
| 39 | + "$var0 lteq $var1" <- Returns $true, if $var0 is less or equal than $var1 (Works only with numbers) |
| 40 | + "$var0 gt $var1" <- Returns $true, if $var0 is greater than $var1 (Works only with numbers) |
| 41 | + "$var0 gteq $var1" <- Returns $true, if $var0 is greater or equal than $var1 (Works only with numbers)# |
| 42 | + |
| 43 | + var0 = 22; |
| 44 | + var1 = 12; |
| 45 | + if ($var0 gt $var1) { |
| 46 | + println "var0 is greater than var1"; |
| 47 | + }; |
| 48 | + |
| 49 | + |
| 50 | +#You can also use logical operators "and" and "or"# |
| 51 | + result0 = ($true and $false); |
| 52 | + println $result0; |
| 53 | + result1 = ($true and $false or $true); |
| 54 | + println $result1; |
| 55 | + result1 = (($true and $false) or ($true and $true)); |
| 56 | + println $result1; |
| 57 | + |
| 58 | +#The following example prints, if x is inbetween 10 and 20 or less than 0# |
| 59 | + x = 20; |
| 60 | + if (($x gteq 10) and ($x lteq 20) or ($x lt 0)) { |
| 61 | + println "x is between 10 and 20 or less than 0"; |
| 62 | + } else { |
| 63 | + println "x is less than 10 and greater than 20 and above zero"; |
| 64 | + }; |
| 65 | + |
0 commit comments