<?xml version="1.0" encoding="windows-1252"?>
<node id="574133" title="Re: exiting two loop levels" created="2006-09-21 10:26:08" updated="2006-09-21 06:26:08">
<type id="11">
note</type>
<author id="72267">
VSarkiss</author>
<data>
<field name="doctext">
&lt;p&gt;[GrandFather] and [davorg] have your answer above.  I just wanted to add that it often reads better to label your loops with what they're iterating over, rather than their structure.&lt;/p&gt;
&lt;p&gt;For example, say you're processing files and records line-by-line.  You could do this:
&lt;code&gt;OUTER:
while ( $more )
{
    INNER:
    while ( $still_more )
    {
        # ...
        last OUTER if $done_with_files;
        last INNER if $done_with_lines;
    }
}
&lt;/code&gt;But it reads better with a change in labels:
&lt;code&gt;FILE:
while ( $more )
{
    LINE:
    while ( $still_more )
    {
        # ...
        last FILE if $done_with_files;
        last LINE if $done_with_lines;
    }
}
&lt;/code&gt;&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-72267"&gt;
&lt;p&gt;&lt;small&gt;&lt;i&gt;[id://149675|Do not rebuke them with harsh words ... but rather lead them gently - with URLs - so that they may learn wisdom.]&lt;/i&gt;&lt;/small&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
574090</field>
<field name="parent_node">
574090</field>
</data>
</node>
