TScript Keywords Control (if..else, switch)

The if..else keyword

else if(condition){...}
else {...}

Here like in C/C++, the "if" keyword can be by itself, with an "else" keyword or with a combination of the two keywords "else if". Preceding the "if" keyword is a conditional statement which will be resolved into a Boolean expression which is either true of false. Also like the C/C++ language, there are braces following the keywords, which allow for a block of preceding code to be execute if the condition is true, if the braces are missing, then only one line of code is executed.

The switch keyword

When a situation of multiple if..else statements occurs, programmers can use a switch statement instead and give a neat layout to maxise the readability of your code. The basic syntax for this keyword is: -

case constant:

In TScript and unlike in C/C++ the case keyword can contain any type of constant, from an integer, string, structure or named constant. Like in C/C++ multiple case statements can be used to execute one block of code when any of the cases are true. The "break" keyword is used to send execution of the script to the end of the switch statement and if not present execution will continue into the next block of code. The "default" keyword is used to indicate the block of code to execute when all case statements fail, once a "default" keyword has been defined, no other case statements can be created.