|
The keyword If allows to choose which part of the code to execute depending on the test condition which can be True or False This could be translated in natural language as "if this happens, then execute this part of the code, else execute the other".
Let see how is the syntax of this instruction:
If Expression Then ... "Block of THEN instructions " executed if Expression = True ... Else ... "Block of ELSE instructions " executed if Expression = False ... EndIf
"Expression" evaluates to a Boolean value. The result must be either True or False. If Expression is True, the code identified as "Block of THEN instructions" will be executed. If Expression is False, the code identified as "Block of ELSE instructions" will be executed. In practice only the following could be written:
If Expression Then ... "Block of THEN instructions" ... EndIf
In this case if Expression is False no code will be executed.
Of course inside these block of code, there could be other If instructions. These are called Nested control structures, when a If keyword is inside another THEN or ELSE block, like in this example.
If Expression1 Then If Expression2 Then ... Else ... Endif Else if Expression3 Then ... Endif Endif
In theory there is no limit of the number of nested instructions, but it is suggested to keep it as simple as possible, for code readability if nothing else.
|