[fpc-pascal] for .. in loop implementation
leledumbo
leledumbo_cool at yahoo.co.id
Wed Jan 7 10:30:20 CET 2009
OK, I've read http://wiki.freepascal.org/Modernised_Pascal this (and the
FAQ as well). I disagree with any statement saying that for .. in loop is
only a type-saver. It's a good language extension and should be included
(since Delphi already have this, it will also be a good idea). Consider the
following example:
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;
The latter one has iteration overheads, while the former can be optimized to
loop as many as needed. I'm not saying I'm the best Pascal programmer, but
in case there's a (better) solution to this (rather than extending the
language) please tell me.
--
View this message in context: http://www.nabble.com/for-..-in-loop-implementation-tp21327686p21327686.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list