So, I'm running into some trouble thinking of how to temporarily leave a for loop, only to return to it later. Ideally I'd like to return to the spot where I left off. I feel like there's some logic I'm missing somewhere.

To start, let's say I have:
-------

#some stuff foreach (@array) { $spot_in_array = $_; #some stuff if(CONDITION_MET){ #temporarily leave foreach } }

In the if statement, how would I leave the foreach loop without leaving permanently? I thought of using last but I know that wouldn't get me back into the loop. The reason why I added that $spot = $_; is because, I think I'm on the right track here, I may be able to use a for loop that starts at $spot and ends at the last index of @array. How I'd do this kind of stumps me. Would I start with a foreach loop at all? Or do I set $spot to the first item, and iterate through a for loop, in a nested while loop that returns every time if(!CONDITION_MET) happens, kind of like an on/off switch.

I've only picked up and been working with Perl for a few weeks, so there's a lot I still don't know. Any help would be greatly appreciated. Thanks.


In reply to Breaking from a foreach loop, returning to position by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.