From: Marcello H <mar...@gm...> - 2006-10-26 10:59:26
|
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 <sha...@gm...>: > > 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 <ke...@xa...> 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 > > > Web...@li... > > > 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 > > Web...@li... > > 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 > Web...@li... > https://lists.sourceforge.net/lists/listinfo/webmacro-user > > > |