Re: Break or Continue in a whiel loop

Keats Kirsch <[email protected]> Wed, 18 Oct 2006 13:14:35 -0400
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
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