First issue
I would like to plot several curves using the \foreach command and
have their number in the sequence as markers.
Here is the code I came up with :
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
1 4 0.2 0.1
2 4.2 0.1 0.5
3 3.1 0.3 0.4
4 2.5 0.25 0.35
}\table
\begin{axis}
\foreach \i in {1,2,3}
\addplot+[text mark={\i}, mark=text] table[x index=0, y index=\i]{\table};
\end{axis}
\end{tikzpicture}
\end{document}
and here is the result it raises :

My problem is that for some reason the text mark={\i} is stuck to
1.
A solution is to use the \pgfplotsinvokeforeach command (see my answer).
Second issue
But now if I need some other index computed from the counter using for instance
\pgfmathsetmacro{\j}{\i+1}% with the \foreach command
I would write
\pgfmathsetmacro{\j}{##1+1}% with the \pgfplotsinvokeforeach command
but this last one does not work. I think the problem is that the #1 is interpreted as if it is supposed to represend an argument of \pgfmathsetmacro. My attempt of doubling the hash did not solve this second issue.