in reply to Re: Re: Re: Re: for loops and 'and'
in thread for loops and 'and'

To explain why the two differ (where the second is just an unwrapped loop, pretty much otherwise equivalent to the first):

Each flipflop operator has its own independent hidden state variable in the pad. It acts like a my $flipflopstate at the top of the enclosing sub or file, only a different variable for each flipflop in the sub/file.

Thus, in your second example, the first 1..10 gets set true (because $. is 1) but none of the later ones are (because they never pass the beginning check for $.==1).

In the first example, the flipflop returns true 10 times because it meets the $.==1 check the first time and doesn't meet the $.==10 check until the 10th time.

Note that because the hidden state acts like sub-scoped lexical, a recursive call to the sub will start with a fresh state, and ditto multiple threads in the same sub.

  • Comment on Re: Re: Re: Re: Re: for loops and 'and'