Any idea, why the following doesn't work and how to fix ist:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[no markers]
\pgfmathsetmacro{\i}{0}
\foreach \f in {sin(deg(x)),x^2}
{
\addplot {\f} node [pos=0.6,right] {\i};
\pgfmathsetmacro{\i}{\i+1};
}
\end{axis}
\end{tikzpicture}
\end{document}
I get the following output:

Edit:
I want that the value of \i in my loop is the same for one pass of the loop regardless if I use \i for a node or something else (which may be related to expanding problems), at the end of the loop I want to set a new value of \i.
Or to say it in other words: I just want to use the variable \i as one would do it in other programming languages inside a loop...

\iin your real application? – Jake Sep 24 '12 at 17:45\iis reset each time around the loop. You could put\global\let\i=\ito make it have effect outside. If you want integers, use\pgfmathtruncatemacroinstead of\pgfmathsetmacro. – Andrew Stacey Sep 24 '12 at 17:54\pgfplotsforeachungroupedinstead of\foreach, but another issue is that thenodecontent is not expanded at the time of the definition, but only at the time of drawing (after the plot is finished), so all nodes would have the same value (the final value of\i). – Jake Sep 24 '12 at 17:58\iseems not to change it's value... – student Sep 24 '12 at 18:00