[fpc-pascal] for .. in loop implementation

dmitry boyarintsev skalogryz.lists at gmail.com
Wed Jan 7 20:11:31 CET 2009


the nice thing about pascal, is that compile support different code
compilers syntax: {$mode ...}

if anyone likes, he/she can implement additional {$mode} for the
compiler, right? this new {$mode} can be included into compiler
packages, and if necesssary anyone can rebuild the compiler to support
this new mode!

there're a lot of threads talking about "it's so cool to have this
feature...". But fpc is open source, so feel free to implement it your
own modes :)

anyway, about topic:

type
 TDays: (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
 TDaySet: set of TDays;
var
 d: TDaySet;
begin
 for d in [Monday,Wednesday,Friday] do ;
 // versus
 for d:=Low(TDaySet) to High(TDaySet) do
   if d in [Monday,Wednesday,Friday] then ;
end;

here's another nice way to implement this without overhead: open-arrays!

procedure DayLoop(const Days: array of TDays);
var
  i : integer;
begin
  for i := 0 to length(Days)  - 1 do
    Days[i]...
end;

...
DayLoop( [Monday,Wednesday,Friday] );
..



More information about the fpc-pascal mailing list