|Top Previous Next|
Here are control structures supported by Tibbo BASIC and Tibbo C. Control structures use relational and logical operators.
Tibbo BASIC supports two distinctive versions of the if-then-else construct: single-line and multi-line.
The single-line version is the only construct in the entire Tibbo BASIC/C domain that must fit entirely on one line of text.
C, of course also has its "single-line" if-then-else that doesn't even use the keywords if, then, and else. I used quotation marks around single-line because C doesn't really care about line breaks. It's just weird to have this construct spill onto more lines.
The multi-line if-then-else version is similar between Tibbo BASIC and C:
Select case / switch()
Differences between Tibbo BASIC and Tibbo C:
In BASIC, there is no need to end each case with a break. It's a must in C!
In BASIC, if you want to combine several values in one case use the syntax like this: case 2,3. If you write case 2: case 3: it will mean that case 2 has no code in it (an empty case). This is the opposite to how C has it.
The switch construct of C is much more efficient. It's realized as a "jump table", while select case of BASIC goes through each case: sequentially. On the other hand, BASIC allows you to define cases that are not constant in value, i.e. case 1+y:. Trying this in C would generate an error — only constant expressions are allowed! This is because the jump table must be built at compile time.
For—next / for()
Tibbo BASIC loops are "inclusive of the last value". If you write for f=0 to 4 this means that the loop will run 5 times (provided the step=1).
Let's see two examples: a simple loop that increments by one, and a loop with a custom step.
Do—loop / do—while()
There are four versions of this in BASIC: do until — loop, do — loop until, do while — loop, do — loop while.
Having the condition check on the front differs from having it on the back: do until — loop and do while — loop may not loop even once, while do — loop until and do — loop while will always go through the loop at least one time.
On the C side this construct has only one form: do—while(). With the check positioned on the back this loop will always run at least once.
While-wend / while()
BASIC and C implementations are identical. The check is on the front, so the loop may run zero times.
Exit for, exit do, exit while (Tibbo BASIC) and break (Tibbo C) statements
In BASIC, exit for, exit do, and exit while abort the current for—next, do—loop/while, or while-wend cycle.
In C, the break statement can abort the current for, do—loop, and while cycle.
Exit and break statements only terminate "their" loop. Outer loops are not affected:
In C, the break statement is also used in the switch construct. It is actually an integral part of it.
I have already provided a code example above.
Exit sub and exit function statements (Tibbo BASIC)
Exit sub and Exit function allow you to finish with the execution of a sub/function at any place in its body.
The equivalent in C is the return statement, but it's use is only possible in non-void functions.
The continue statement (Tibbo C)
For, do—loop, and while constructs of C can also use the continue statement. It skips whatever is left in the loop's body and jumps straight to the next loop pass.
No equivalent exists in Tibbo BASIC.
And don't forget... the goto statement
Some argue that no sensible language (or developer) needs the goto statement, ever. Yet, the humble goto exists and persists.
In Tibbo BASIC and Tibbo C, labels must end with a colon (:), or they won't be recognized as such. This only applies to places where labels are placed, not to the goto statement itself.
The scope of labels is limited to the procedure (function) they are in. This is because you can't use the goto statement to jump from one procedure into another.
Consequently, you can use the same label name in multiple procedures.