JeeWiz Home  
The Model-Driven System Builder

JeeWiz Architect's Guide
 
Contents  >   8.  Templates and Velocity Features
 


8.7 #while and #break/#continue

These directives are additional to standard Velocity. #while gives an alternative to #foreach. #break/#continue and their '2' variants give more control within #foreach and #while.

These directives are relatively new and so there are currently not many examples of their use in the codebase (as of verson 5.0).

 8.7.1  The #while directive
 8.7.2  Loop Control Directives: #break and #continue

8.7.1  The #while directive
The #while directive allows you to construct a loop without using specific values like the #foreach loop does.

The syntax is as follows:
  1. Option 1 - using a conditional expression:
    #while( expression )
       statements+
    #end
  2. Option 2 - no expression, - and the '()' is normally omitted too:
    #while
       statements+
    #end
    This is equivalent to a version 1 where the expression is "true". To terminate this loop, there must be a #break statement executed.
There must be at least one statement as the body of the #while - just as #foreach.
8.7.2  Loop Control Directives: #break and #continue
Just like Java, the #break directive breaks out of an enclosing loop; the #continue directive starts another go-round of an enclosing loop. #foreach and #while are the loop directives.

There are also 2-loop variants: the #break2 and #continue2.

If the loop control directives are not in the necessary loop directive, this causes a runtime exception.  


Copyright (c) 2001-2008 New Technology/enterprise Ltd.