# Using \evaluate in nested \foreach loops with TikZ

I would like to draw two grids side by side using TikZ; the left one being a complete square grid, and the right one being a lower-triangular one. I tried writing the following code to make the figure, but \yy is always equal to \y, and it only draws straight lines. What am I doing wrong? Is there a better way to draw the triangular grid?

\begin{tikzpicture}
% Grid
\draw[step=1,color=gray] (0,0) grid (5,5);
\draw (4.5,4.5) node {G};

\foreach \x [evaluate=\x as \ystart using int(\x-6), evaluate=\x as \xx using int(\x+1)] in {6, 7,..., 10}
\foreach \y [evaluate=\y as \yy using int(\y+1)] in {\ystart, ..., 4}
\draw [color=gray] (\x,\y) rectangle (\xx,\yy) node {\y, \yy} ;
\draw (10.5,4.5) node {G};

\end{tikzpicture}

-

You need to enclose the content of the \foreach loop in curly braces:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
% Grid
\draw[step=1,color=gray] (0,0) grid (5,5);
\draw (4.5,4.5) node {G};

\foreach \x [evaluate=\x as \ystart using int(\x-6), evaluate=\x as \xx using int(\x+1)] in {6, 7,..., 10}{
\foreach \y [evaluate=\y as \yy using int(\y+1)] in {\ystart, ..., 4}{
\draw [color=gray] (\x,\y) rectangle (\xx,\yy) node {\y, \yy} ;
}
}

That's odd behaviour. I thought that for single-command \foreachs then there was no need to enclose like this. –  Loop Space Oct 17 '11 at 6:55
@AndrewStacey: The braces are technically only required for the outer \foreach, the inner one works as expected. –  Jake Oct 17 '11 at 6:57