1

The question is already in the title. I am using "algorithmic" as package and can not find any reference for "FOREACH" definition. I already know that for "algpseudocode" I could use

% define macro foreach
\algnewcommand\algorithmicforeach{\textbf{for each}}
\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}

But I can not find something similar for "algorithmic".

2 Answers 2

1

You can copy the content that is created for \FORALL and replace the necessary elements to create a \FOREACH:

enter image description here

\documentclass{article}

\usepackage{algorithmic}

\makeatletter
% Taken from \FORALL within
%   http://mirrors.ctan.org/macros/latex/contrib/algorithms/algorithms.dtx
\newcommand{\algorithmicforeach}{\textbf{for each}}
\newcommand{\FOREACH}[2][default]{%
  \ALC@it\algorithmicforeach\ #2\ \algorithmicdo%
    \ALC@com{#1}\begin{ALC@for}}
\makeatother

\begin{document}

\begin{algorithmic}[1]
  \FORALL{$i$ such that $0 \leq i \leq 10$}
    \STATE carry out some processing
  \ENDFOR
  \FOREACH{$i$ such that $0 \leq i \leq 10$}
    \STATE carry out some processing
  \ENDFOR
\end{algorithmic}

\end{document}
0

I did just realize that there seems to be "FORALL" in algorithmic, so one can do:

\begin{algorithmic}[1]
\FORALL{$i$ such that $0\leq i\leq 10$}
\STATE carry out some processing
\ENDFOR
\end{algorithmic}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.