mako icon indicating copy to clipboard operation
mako copied to clipboard

continue / break control statements?

Open sqlalchemy-bot opened this issue 14 years ago • 3 comments

Migrated issue, originally created by Anonymous

Hi,

I was wondering how to use control/break within a loop. I didn't find anything in the docs, so I tried this:

% for i in range(10): % if i == 3: % continue % endif ${i} % endfor

That didn't work, so I ended up with this:

% for i in range(10): <% if i == 3: continue %> ${i} % endfor

I find the first version is more readable. Perhaps it would be nice to have 'continue' and 'break' statements to complement the flow control.

Alternatively, if there's another preferred method for issuing a continue or break, it would be great to have an example in the docs.

Thanks!

sqlalchemy-bot avatar Aug 06 '10 13:08 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

% X / % endX are kind of meant to be in pairs. I don't see how 'continue', 'break', or 'return' could work it's way in there. We already document 'return' as:

<% return %>

so in this case you only need:

% for i in range(10):

    % if i == 3:

        <% continue %>

    % endif ${i}

% endfor 

its pretty readable to me.

sqlalchemy-bot avatar Aug 06 '10 17:08 sqlalchemy-bot

Anonymous wrote:

Thanks!

sqlalchemy-bot avatar Aug 07 '10 10:08 sqlalchemy-bot

Anonymous wrote:

Could you please add this to the documentation, section "Control Structures"? It's not really straigthforward that 'continue' and 'break' should be written this way based on the 'return' example. For example I only figured it out after finding this ticket.

Thanks!

sqlalchemy-bot avatar Sep 30 '11 10:09 sqlalchemy-bot