© Tyl Software Foundation 2019-2021
▶ CONDITIONAL STATEMENT
Conditional statement is a statement that directs the program flow based
on a condition.
Conditional statement with yes block only structure:
Conditional statement with yes and no blocks structure:
Conditional statement has two or three components:
[CONDITION] ?
[STATEMENT] yes block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is TRUE
ᐤ
[STATEMENT] yes block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is TRUE
ᐤ
Conditional statement with yes and no blocks structure:
[CONDITION] ?
[STATEMENT] yes block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is TRUE
⇋
[STATEMENT] no block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is FALSE
ᐤ
[STATEMENT] yes block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is TRUE
⇋
[STATEMENT] no block: statements
[STATEMENT] that will be executed
[STATEMENT] if the condition is FALSE
ᐤ
Conditional statement has two or three components:
- condition statement
- yes block
- no block (optional)
Condition statement type can be:
- variable condition
- statement condition
- compare condition
Conditional Statement Composition
A condition statement signature looks like:
esverdad ?
The line '
In this code:
esverdad ?
', is the condition line. The esverdad
is the condition
statement, of variable condition type, and the question mark '?', is Tyl symbol
for conditional statements.
In this code:
esverdad \t
esverdad ?
print 'Si'
^
The characters combination '\t' is Tyl code for TRUE, and is replaced by the symbol
'
The above code will look like:
t
', which is Tyl symbol for TRUE. The caret '^', is Tyl code for
end statement, and is replaced by
'ᐤ
'. Tyl needs an end statement, to know where the yes block ends.
The above code will look like:
esverdad t
esverdad ?
print 'Si'
ᐤ
Si
If there is only one statement in the yes block, it is posible to write the yes
statement
right after the condition:
esverdad ? print 'Si'
The line
esverdad ? print 'Si'
, is called a one line conditional statement,
and is good for short conditional statements.