Does python mako template support connect / break in loop context?

Is it possible to use continue / break in the loop of the% control structure.

For example:

% for x in range(1): % continue % endfor 

Thanks,

+7
source share
1 answer

Yes. You use <% continue %> and <% break %> .

Example:

 from mako.template import Template t = Template( """ % for i in xrange(5): % if i == 3: <% break %> % endif ${i} % endfor % for i in xrange(5): % if i == 3: <% continue %> % endif ${i} % endfor """) print t.render() 

Exit:

 0 1 2 0 1 2 4 
+15
source

All Articles