I want to draw something in tikz where the range of an inner loop depends on an outer loop (by construction of the math involved). I need to differentiate between even and odd number in the inner loop, and so my first approach was to define the range \foreach \ell in {[begin],[begin+2],...,[end]} and then deal with \ell and \ell+1 separately in the loop (this code with square brackets cannot run, for the actual example see MWE below).
The problem is that - contrary to my expectation - for the the smallest range that occurs, tikz evaluates \foreach \ell in {-1,1,...,-1} as \ell in {-1,1}). The documentation (p.910) says (square bracket and emphasis mine):
In this situation, the part of the list reading
x,y,...,zis replaced byx,x+d,x+2d,...,x+md, where [d=y-xand] the last dots are semantic dots, not syntactic dots. The valuemis the largest number such thatx+md<=zifdis positive or such thatx+md>=zifdis negative.
My interpretation would be that m should be 0 in my case, but maybe that's hard to actually implement - or the behaviour could even be intentional.
In any case, I'd like to avoid having to split the loops and would like to find a way around it. I guess it would be possible to build an if-clause depending on the parity of \ell (to distinguish between even and odd, and just avoid specifying the second value of the list), this is just not that elegant either IMHO. But maybe there's no way around that as things stand...
As a brief sketch how I'd like my code to look like, here's an MWE (the desired result should just be one node at (1,1) with label "1"):
\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \j in {1} % scale (normally more!)
{
% do something per scale here
\pgfmathsetmacro{\z}{2^(\j-1)}
\pgfmathsetmacro\istart{-\z}
\pgfmathsetmacro\isecond{\istart+2}
\pgfmathsetmacro\iend{\z-2}
\foreach \ell in {\istart,\isecond,...,\iend}
{
% do something for \ell here
\node at (\ell,\ell) {\ell}; % just for illustration
% do something for \ell+1 here
}
}
\end{tikzpicture}
\end{document}

pgfforalways evaluates at least 2 values, the first one, and the second one. Only then it cares about the upper bound. It should have been stated in the manual. However, I'm sure that this has been asked before here :) I just can't find it now... – yo' Oct 07 '14 at 09:54m=0. – Axel Oct 07 '14 at 09:59