2014-12-06 7 views
1

저는 LaTex에서 루프를 만들려고하지만, 처음으로 만 출력됩니다. 여기 내가 무슨 일을하는지 요지가 있지만 루프가 제대로 작동하지 않습니다.라텍스의 루프가 작동하지 않습니다.

\documentclass[12pt]{article} 

%%% FOR LOOP CODE 
\usepackage{ifthen} 
\newcommand{\forLoop}[5][1]{% 
    \setcounter{#4}{#2} % 
    \ifthenelse{ \value{#4}<#3 }% 
    {% 
    #5 % 
    \addtocounter{#4}{#1} % 
    \forLoop[#1]{\value{#4}}{#3}{#4}{#5} % 
    }% 
    {% 
    #5 % 
    }% 
    }% 
%% END FOR LOOP CODE 

\begin{document} 

Practice loop 
\newcounter{index} 

\section{Example 1} 

\forLoop[2]{1}{5}{index} 
{ 
    This is inside the for loop: iteration \theindex\\ 
} 

\end{document} 

답변

1

a number of ways to create a loop in LaTeX있다, 그래서 바퀴를 다시 발명 할 필요가 없습니다 :

enter image description here

\documentclass{article} 

\usepackage{multido} 
\newcommand{\forLoop}[4][1]{\multido{\i=#2+#1}{#3}{#4}} 

\setlength{\parindent}{0pt}% Just for this example 
\begin{document} 

\section{Example} 

\forLoop[2]{1}{5} 
{% 
    This is inside the for loop: iteration \i\endgraf 
} 

\end{document}