-
Notifications
You must be signed in to change notification settings - Fork 0
Control Flow
Unlike C, at the end of each control flow, a semicolon is needed. The articles below will omit them.
Although not a control flow, all of the following (including each case clause, but not Gotos) will create a new scope. Variables declared inside a scope will be destroyed as soon as they leave it.
For example:
i = 5 : int;
do
i = 10 : int;
end; # The i (10) will be destroyed here
j = i : int; # The i here is the one with the value of 5.
Despite the famous Go To Statement Considered Harmful, it remained as one of the control flows in CTalk. To create a new label:
$<identifier>: <statement>
The statement is obligatory.
To goto a label:
goto $<identifier>
if <expression>
<statements>
elseif <expression>
<statements>
else
<statements>
end
There can be none (or many) elseif clauses and the else clause can be omitted (no more than one).
Similar to Go, in CTalk, while loops and for loops are unified as one. That had been said, there is no equivalent of a do-while loop.
As a while loop:
for <expression>
<statements>
end
As a for loop:
for <expression>, <expression>, <expression>
<statements>
end
In the for loop case, the expressions can be omitted.
switch <expression>
case <expression>:
<statements>
default:
<statements>
end
The expression for each case follows the same restrictions as the one specified by C.
Basically all case expressions have to be constants. There can be none (or many) case
clauses and at most one default clause. There is no fixed position for were the default
clause must go.