# \foreach from 1 to 1 [duplicate]

This question already has an answer here:

How to make a command (without testing) that contains a foreach loop that may count from 1 to 1 if necessary ?

\documentclass{minimal}
\usepackage{tikz}

\newcommand{\boucle}[1]{%
\foreach \x in {1,2,...,#1} {\x }
}

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}


-

## marked as duplicate by ChrisS, Werner, Claudio Fiandrino, Svend Tveskæg, GuidoMar 6 '14 at 7:29

Thank to both of you. – Tarass Mar 6 '14 at 5:35

Remove the second item.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{pgffor}

\newcommand{\boucle}[1]{%
\foreach \x in {1,...,#1} {\x }
}

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}


-
For the specific case, it is possible to load the sole pgffor package rather than tikz. – Claudio Fiandrino Mar 6 '14 at 6:36

Use it without a second member (which would denote the step):

\documentclass{article}
\usepackage{tikz}% http://ctan.org/pkg/tikz

\newcommand{\boucle}[1]{\foreach \x in {1,...,#1} {\x }}

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}


The same result could be achieved using multido:

\usepackage{multido}% http://ctan.org/pkg/multido
\newcommand{\boucle}[1]{\multido{\i=1+1}{#1}{\i}}


Other options also exist, of course.

-
For the specific case, it is possible to load the sole pgffor package rather than tikz. – Claudio Fiandrino Mar 6 '14 at 6:35