Eike Lange wrote:
The following program compiles without warnings:
{ 2.1 (20020510), based on gcc-2.95.2 19991024 (release) } program bug;
var i: Integer = 1;
begin if i = 1 then WriteLn ('is 1') else if i = 2 then { do nothing } else { do nothing } end.
Not a bug. Terrible program structure, leading to much confusion, but valid. The null statement is specifically permitted. You will often see such things as:
WHILE whatever DO (* nothing *);
With if/else if/else chains, a useful rule is to put the short clauses first (if possible) and make the final else the longest clause. i.e.:
IF something THEN BEGIN (* lots of code *) END ELSE BEGIN (* a few lines *) END;
is inferior to:
IF NOT something THEN BEGIN (* a few lines *) END ELSE BEGIN (* lots of code *) END;
for readability reasons. You can look up from any code and find the controlling statement easily. This applies to most languages. The compiler should normally be able to optimize away any extra code generated.