for a := 0 to x do
for b := 0 to y do
  for c := 0 to z do
     if (...) then
     begin
         // Do something and then exit all loops
         exit;  // Or maybe: goto OutSideOfLoops;
     end;

In Pascal I can't change the 'a' and 'b' values to force the end of the loop. So what other GOOD option do I have but to use exit or goto?

Use a while or repeat loop. The whole point of a for-loop is exactly to have the compiler ensure (to the best of its abilities) that you do not accidentally modify the loop variables.

Well, if you think an exit is ugly, image changing this code into while loops. May as well use assembly.

OT: The only things I dislike about pascal is that the value of a variable at the end of a for loop is undefined. It should remain at the value it had when exiting the loop.

Andreas

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to