in reply to at continue, last

I need to ensure that a variable is decremented regardless of how an if clause is exited,

Then do the decrement before entering the if:

... --$loop; if( condition1 ) { { ... last if condition2; ... } }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: at continue, last
by Anonymous Monk on Jun 06, 2014 at 16:32 UTC
    That'll break the program's logic; $loop may only be decremented within the conditional (otherwise, yes, I'd put it outside of it).
      That'll break the program's logic; $loop may only be decremented within the conditional (otherwise, yes, I'd put it outside of it).

      I that case, decrement it as the first thing in the conditional, then you're guaranteed it'll happen.

      The point is that, as described, there is no reason to employed contorted logic to achieve the described requirement.

      Perhaps in an attempt to simplify the original code you've omitted something that makes the contorted logic necessary, but as posted, it simply isn't needed.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I replied to another similar comment elsewhere; $loop is used in the conditional, so decrementing it before I use it means I have to increment it every time I use it.
        The point of the posting was to examine different ways of solving the underlying problem, namely ensuring that there's a single path to cleanup code in a conditional, and the obscure means by which it could be achieved. Perhaps that would have been a better introduction.