Re: Break or Continue in a whiel loop
"Shane Farmer" <[email protected]> Tue, 31 Oct 2006 21:58:37 +1000
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
--===============0414533000== Content-Type: multipart/alternative; boundary="----=_Part_5535_4731968.1162295917841" ------=_Part_5535_4731968.1162295917841 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks for that, but that doesn't help my current problem as we are stuck using a customised version of 1.1 and moving to 2.0 is not really an option at the moment (long story). The basic version I have is working fine as it is only being used in fairly basic cases. Maybe I will investigate this a little further when I get more time. Thanks for all the help. Shane On 10/26/06, Marcello H <[email protected]> wrote: > > I don't understand this. > There has been a while loop, with some extra special features, written by > Mike Weerdenburg. > > He did send it by mail to the group, since he was unable to put in cvs at > that time. > But somebody did check it in (perhaps I did, I don't know). > But I'm preety sure it works, since I use it a lot. > > If you grab the lastest code out of cvs, you will see the while directoive > in the directive directory. > > /** > * Syntax: #while (condition) [limit (int)] { block } WhileDirective > implements a WebMacro directive for an while > * control structure. If you use it without the limit option than it stops > after 1000000 loops! > * Use a limit value < 0 to create a loop without a limit, this could hang > your template! > * Introduced at release 2.0 as an experimental directive. > */ > > Works as should! > > Greeting form Holland, > and good luck > > Marcel > > > > > > 2006/10/19, Shane Farmer < [email protected]>: > > > > 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 > > > > > > > > > > > ------------------------------------------------------------------------- > > 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_5535_4731968.1162295917841 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks for that, but that doesn't help my current problem as we are stuck using a customised version of 1.1 and moving to 2.0 is not really an option at the moment (long story).<br><br>The basic version I have is working fine as it is only being used in fairly basic cases. Maybe I will investigate this a little further when I get more time. <br><br>Thanks for all the help.<br>Shane<br><br><div><span class="gmail_quote">On 10/26/06, <b class="gmail_sendername">Marcello H</b> <<a href="mailto:[email protected]">[email protected]</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I don't understand this.<br>There has been a while loop, with some extra special features, written by Mike Weerdenburg.<br><br>He did send it by mail to the group, since he was unable to put in cvs at that time.<br>But somebody did check it in (perhaps I did, I don't know). <br>But I'm preety sure it works, since I use it a lot.<br><br>If you grab the lastest code out of cvs, you will see the while directoive in the directive directory.<br><br>/**<br> * Syntax: #while (condition) [limit (int)] { block } WhileDirective implements a WebMacro directive for an while <br> * control structure. If you use it without the limit option than it stops after 1000000 loops!<br> * Use a limit value < 0 to create a loop without a limit, this could hang your template!<br> * Introduced at release 2.0 as an experimental directive.<br> */<br><br>Works as should!<br><br>Greeting form Holland,<br>and good luck<br><br>Marcel<br><br><br><br><br><br><div><span class="gmail_quote">2006/10/19, Shane Farmer <<a href="mailto:[email protected]" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> [email protected]</a>>:</span><div><span class="e" id="q_10e84465171d3d7a_1"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Thanks Keats for the words of wisdome. I think that has given me everything I need to finish it off. </div> <div> </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><span> <div> </div> <div>Shane<br> </div></span><div><span> <div><span class="gmail_quote">On 10/19/06, <b class="gmail_sendername">Keats Kirsch</b> <<a href="mailto:[email protected]" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">[email protected]</a>> wrote: </span> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">The directive code looks pretty clean, but I'd question the need for<br>it. 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. 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 = "Bad") { #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. This could be handled by using labels, like in Java. <br><br>#foreach $list in $collection label "outerloop" {<br> #foreach $item in $list {<br> #if ($item = "Bad") { #break "outerloop" }<br> }<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. 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>> Hi All,<br>><br>> I have been looking around for a while loop to no avail. As such I <br>> have implimented a very basic while loop directive. I am using an<br>> older version of WM (1.0 or 1.1) and was wondering if it possible to<br>> create 2 subdirectives, break and continue, and if anyone would have <br>> some pointers on how to go about doing this.<br>><br>> The code is _very_ basic ATM and simply loops while ever the<br>> conditional arg is true and evaluates [block.write(...)] on the block arg.<br>> <br>> Im am all ears for better design startegies for this directive as well.<br>><br>> Thanks in advance<br>> Shane<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&kid=120709&bid=263057&dat=121642" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 </a><br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> Webmacro-user mailing list<br>> <a href="mailto:[email protected]" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> [email protected]</a><br>> <a href="https://lists.sourceforge.net/lists/listinfo/webmacro-user" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">https://lists.sourceforge.net/lists/listinfo/webmacro-user </a><br>><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&kid=120709&bid=263057&dat=121642" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 </a><br>_______________________________________________ <br>Webmacro-user mailing list<br><a href="mailto:[email protected]" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">[email protected]</a><br><a href="https://lists.sourceforge.net/lists/listinfo/webmacro-user" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> https://lists.sourceforge.net/lists/listinfo/webmacro-user </a><br></blockquote></div><br> </span></div><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&kid=120709&bid=263057&dat=121642" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642</a><br><br>_______________________________________________<br>Webmacro-user mailing list<br><a href="mailto:[email protected]" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> [email protected]</a><br><a href="https://lists.sourceforge.net/lists/listinfo/webmacro-user" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">https://lists.sourceforge.net/lists/listinfo/webmacro-user </a><br><br><br></blockquote></span></div></div><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 onclick="return top.js.OpenExtLink(window,event,this)" href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642" target="_blank"> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642</a><br><br>_______________________________________________<br>Webmacro-user mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:[email protected]"> [email protected]</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/webmacro-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/webmacro-user </a><br><br><br></blockquote></div><br> ------=_Part_5535_4731968.1162295917841-- --===============0414533000== 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 --===============0414533000== 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 --===============0414533000==--