From f0e751aed9dcd3559c9cbaa327c4313f9efdf6b8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 20 Nov 2011 10:20:20 +0100 Subject: [PATCH] added a note about using the loop variable in a for condition --- doc/tags/for.rst | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/doc/tags/for.rst b/doc/tags/for.rst index bbd5caf..6eed3b4 100644 --- a/doc/tags/for.rst +++ b/doc/tags/for.rst @@ -89,6 +89,14 @@ items. The following example skips all the users which are not active: The advantage is that the special loop variable will count correctly thus not counting the users not iterated over. +.. note:: + + Using the ``loop`` variable within the condition is not recommended as it + will probably not be doing what you expect it to. For instance, adding a + condition like ``loop.index > 4`` won't work as the index is only + incremented when the condition is true (so the condition will never + match). + If no iteration took place because the sequence was empty, you can render a replacement block by using ``else``: -- 1.7.2.5