Re: Break or Continue in a whiel loop

"Shane Farmer" <[email protected]> Thu, 19 Oct 2006 09:06:55 +1000
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
--===============0643593666==
Content-Type: multipart/alternative; 
	boundary="----=_Part_7485_23860354.1161212815321"

------=_Part_7485_23860354.1161212815321
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks Keats for the words of wisdome. I think that has given me everything
I need to finish it off.

The main reason for coding a while loop was to help another developer out.
Maybe #count would have worked better for him.

Shane

On 10/19/06, Keats Kirsch <[email protected]> wrote:
>
> The directive code looks pretty clean, but I'd question the need for
> it.  We've discussed a #while directive many times over the years, and I
> have yet to see a use-case that couldn't be handled pretty well by
> #foreach or #count.  The general feeling was always that #while is too
> dangerous because it makes it too easy for a template designer to
> introduce infinite loops.
>
> However I think a #break directive or subdirective might be useful.
> One approach might be to add an option to the directive, like:
>
> #foreach $var in $collection breakon $break {
> #if ($var = "Bad") { #set $break = true }
> }
>
> Then the directive could just check the value of the break variable.
>
> The problem with a break directive is that you would have to deal with
> nested loops.  This could be handled by using labels, like in Java.
>
> #foreach $list in $collection label "outerloop" {
>   #foreach $item in $list {
>      #if ($item = "Bad") { #break "outerloop" }
>   }
> }
>
> This would be harder than the first option, and not any better really
> IMHO.
>
> I don't think #continue would be useful.  It would be difficult to code
> and you can always use an #if instead, which is cleaner anyway.
>
> Keats
>
> Shane Farmer wrote:
> > Hi All,
> >
> > I have been looking around for a while loop to no avail. As such I
> > have implimented a very basic while loop directive. I am using an
> > older version of WM (1.0 or 1.1) and was wondering if it possible to
> > create 2 subdirectives, break and continue, and if anyone would have
> > some pointers on how to go about doing this.
> >
> > The code is _very_ basic ATM and simply loops while ever the
> > conditional arg is true and evaluates [block.write(...)] on the block
> arg.
> >
> > Im am all ears for better design startegies for this directive as well.
> >
> > Thanks in advance
> > Shane
> > ------------------------------------------------------------------------
> >
> >
> -------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services,
> security?
> > Get stuff done quickly with pre-integrated technology to make your job
> easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Webmacro-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/webmacro-user
> >
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Webmacro-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/webmacro-user
>

------=_Part_7485_23860354.1161212815321
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div>Thanks Keats&nbsp;for the words of wisdome. I think that has given me everything I need to finish it off.</div>
<div>&nbsp;</div>
<div>The main reason for coding a while loop was to help another developer out. Maybe #count would have worked better for him.</div>
<div>&nbsp;</div>
<div>Shane<br>&nbsp;</div>
<div><span class="gmail_quote">On 10/19/06, <b class="gmail_sendername">Keats Kirsch</b> &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">The directive code looks pretty clean, but I'd question the need for<br>it.&nbsp;&nbsp;We've discussed a #while directive many times over the years, and I
<br>have yet to see a use-case that couldn't be handled pretty well by<br>#foreach or #count.&nbsp;&nbsp;The general feeling was always that #while is too<br>dangerous because it makes it too easy for a template designer to<br>introduce infinite loops.
<br><br>However I think a #break directive or subdirective might be useful.<br>One approach might be to add an option to the directive, like:<br><br>#foreach $var in $collection breakon $break {<br>#if ($var = &quot;Bad&quot;) { #set $break = true }
<br>}<br><br>Then the directive could just check the value of the break variable.<br><br>The problem with a break directive is that you would have to deal with<br>nested loops.&nbsp;&nbsp;This could be handled by using labels, like in Java.
<br><br>#foreach $list in $collection label &quot;outerloop&quot; {<br>&nbsp;&nbsp;#foreach $item in $list {<br>&nbsp;&nbsp;&nbsp;&nbsp; #if ($item = &quot;Bad&quot;) { #break &quot;outerloop&quot; }<br>&nbsp;&nbsp;}<br>}<br><br>This would be harder than the first option, and not any better really IMHO.
<br><br>I don't think #continue would be useful.&nbsp;&nbsp;It would be difficult to code<br>and you can always use an #if instead, which is cleaner anyway.<br><br>Keats<br><br>Shane Farmer wrote:<br>&gt; Hi All,<br>&gt;<br>&gt; I have been looking around for a while loop to no avail. As such I
<br>&gt; have implimented a very basic while loop directive. I am using an<br>&gt; older version of WM (1.0 or 1.1) and was wondering if it possible to<br>&gt; create 2 subdirectives, break and continue, and if anyone would have
<br>&gt; some pointers on how to go about doing this.<br>&gt;<br>&gt; The code is _very_ basic ATM and simply loops while ever the<br>&gt; conditional arg is true and evaluates [block.write(...)] on the block arg.<br>&gt;
<br>&gt; Im am all ears for better design startegies for this directive as well.<br>&gt;<br>&gt; Thanks in advance<br>&gt; Shane<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>
&gt; -------------------------------------------------------------------------<br>&gt; Using Tomcat but need to do more? Need to support web services, security?<br>&gt; Get stuff done quickly with pre-integrated technology to make your job easier
<br>&gt; Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo<br>&gt; <a href="http://sel.as-us.falkag.net/sel?cmd=lnk&amp;kid=120709&amp;bid=263057&amp;dat=121642">http://sel.as-us.falkag.net/sel?cmd=lnk&amp;kid=120709&amp;bid=263057&amp;dat=121642
</a><br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; Webmacro-user mailing list<br>&gt; <a href="mailto:[email protected]">
[email protected]</a><br>&gt; <a href="https://lists.sourceforge.net/lists/listinfo/webmacro-user">https://lists.sourceforge.net/lists/listinfo/webmacro-user</a><br>&gt;<br><br><br><br>-------------------------------------------------------------------------
<br>Using Tomcat but need to do more? Need to support web services, security?<br>Get stuff done quickly with pre-integrated technology to make your job easier<br>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<br><a href="http://sel.as-us.falkag.net/sel?cmd=lnk&amp;kid=120709&amp;bid=263057&amp;dat=121642">http://sel.as-us.falkag.net/sel?cmd=lnk&amp;kid=120709&amp;bid=263057&amp;dat=121642</a><br>_______________________________________________
<br>Webmacro-user mailing list<br><a href="mailto:[email protected]">[email protected]</a><br><a href="https://lists.sourceforge.net/lists/listinfo/webmacro-user">https://lists.sourceforge.net/lists/listinfo/webmacro-user
</a><br></blockquote></div><br>

------=_Part_7485_23860354.1161212815321--


--===============0643593666==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
--===============0643593666==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Webmacro-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/webmacro-user

--===============0643593666==--