On 2008-Dec-3, at 12:38 pm, Mark J. Reed wrote:
Overall, the goal is to ensure that by the end of the loop the program is in the state of having just called doSomething(), whether the loop runs or not - while also ensuring that the program is in that
state at the top of each loop iteration.
... including the first, just to point out the problem.
[...] I think the cleanest solution is the "coy" one.


Me too. I don't think having the condition in the middle of the block is necessarily a bad thing -- that's how the logic is actually working, after all. Fake conditions like "while(1)" are kind of ugly, but P6 has "loop", and you can always make it stand out more:

loop
{
      doSomething();

   #CHECK OUR LOOP CONDITION!
   last unless someCondition;

      doSomethingElse();
}


Now for my own loop-related question: FIRST{} can do something on only the first iteration through the loop, but there's no NOT-FIRST block to do something on the second and subsequent iterations. Is there an elegant way to do something on all but the first loop?


-David

Reply via email to