Original BASIC had form IF condition THEN commands <EndOfLine>. False means "skip to next line" while true means continue execution (on same line). Indeed, it is very simple concept that can be implement easily.
Introducing ELSE increases complexity a lot, especially when ENDIF is ommited.
Different BASICs came with different solutions:
- introducing IF-ELSE-ENDIF with mandatory ENDIF
- single line IF-THEN with optional ELSE and only one IF is allowed on line
- single line IF-THEN with optional ELSE. Multiple IFs Are allowed and single ELSE branch is taken as alternative for any failed IF
- single line IF-THEN with optional ELSE. Multiple IFs are allowed and single ELSE is alternative for the last IF.
- single line IF-THEN with optional ELSE. Multiple IFs are allowed and multiple ELSEs are allowed. Interpret tries to figure out what ELSE is counterpart to what IF. This task can be solved with assumption that every IF has ELSE or there Is no ELSE on line at all.
Some BASICs allowed both single line IF-THEN and multiline IF-THEN-ELSE-ENDIF, considering line with IF-THEN without any following command as start of multiline IF-THEN-ELSE-ENDIF.
That somehow works but it is mess.
IMHO the original single line IF-THEN has its beauty in context of line oriented BASIC. When BASIC wants use both single and multiline IFs, it should probably solve it with different syntax. For example IF-THEN for single line and IF-BEGIN-ENDIF for multiline statement. It is not accident Pascal uses BEGIN-END for coumpound statements, it makes life easier.
Another mess are procedures. There is concept of local variables, but results are returned in parameter passed as reference. Even if procedure could return result in proper way, without structures or records or objects, you sometimes need to return a tuple eg.
Code: Select all
LET x,y=PROC(a,b,c)
Besides, DO statements WHILE (condition) statements REPEAT loop can mimic any of them and is cleaner, IMHO.