One of the most useful programming constructs in any programming language is flow control. The if statement is the simplest flow control construct.
In YASS, an if statement follows a structure similar to VB.NET. There are only two essentials of an if statement, that is, the
if at the start and the
end if at the end.
The following code sample demonstrates the structure of an if statement in YASS:
if (x ? y) //Do something here end if
Where x and y represent some variables and ? represents a conditional operator. For example:
if (10 > 5) print("Yes") $v = true end if
If statement in YASS can also be shortened using the
if x ? y then //Do something here
if 10 > 5 then print("Yes")
Whilst from time to time it maybe handy to use the shorthand syntax, it is often the case that the full syntax is easier to read.
thenkeyword that brackets should be omitted from the condition.
If a condition is not satisified it evaluates to false. When this happens an if statement will ignore the code on the inside of the statement and will not execute it. This is where else statements come in.
If the condition evaluates to false and an else statement is provided then the program will execute the code within the else statement.
if (10 > 5) print("Yes") $v = true else print("No") $v = false end if
Note that else statement can also be used with the shorthand syntax if statement.
if 10 > 5 then print("Yes") else print("No")
The usual rule of one expression after the
then keyword applies to the code after the