Most Pascal control structures make sense to me, like:
for ... do {statement};
if (condition) then {statement};
while (condition) do {statement};
where the {statement} is either a single statement, or a begin ... end block. I have a problem with:
repeat {statement-list} until (expression);
try {statement-list} except {statement-list} end;
Wouldn't it be better that repeat and try have the same general structure, accepting only a single statement or a begin ... end block, instead of having a statement-list that's not formally blocked with a begin and an end?
The forms that require a begin/end all exist on a single line--the compiler has no other way to know where the block ends. The forms that don't require a begin/end have a closing structure that tells the compiler where it ends and thus the begin/end would simply be redundant. You're free to use it in this case if you want, though.
Niklaus Wirth (the designer of Pascal) corrected these inconsistences in his next language, Modula-2. In Modula-2, compound statements like IF
have no BEGIN
and a mandatory END
:
IF {condition} THEN
{statement-list}
END;
Other control structures such as WHILE
are similar and consistent with REPEAT
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With