0
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\caption{foo}
\begin{algorithmic}[1]
\STATE let $S$ represent ..
\STATE let $P$ represent ..
\STATE let $N$ represent ..
\FORALL {$p \gets Rand(0,P) $}
\FORALL{$i \gets Rand(0,n)$} 
\STATE Select $j \gets Rand(0,n)$ \\
$S[p,j], S[p,i] \gets S[p,i], S[p,j]$
\ENDFOR
\ENDFOR
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{document}

enter image description here

Su__
  • 1
  • 1

1 Answers1

1

This answer assumes you use the combination of the algorithm and algorithmic packages (this information was not provided in the question).

The syntax for \FORALL is that the definition of the loop variable is in brackets but the loop body is not in brackets. The body is assumed to be everything until the corresponding \ENDFOR statement.

MWE:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{minipage}{0.66\textwidth}
\begin{algorithm}[H]
\caption{foo}
\begin{algorithmic}[1]
\STATE let $S$ represent ..
\STATE let $P$ represent ..
\STATE let $N$ represent ..
\FORALL{$p \gets Rand(0,P) $}
\FORALL{$i \gets Rand(0,n)$} 
\STATE Select $j \gets Rand(0,n)$ \\
$S[p,j], S[p,i] \gets S[p,i], S[p,j]$
\ENDFOR
\ENDFOR
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{document}

Result:

enter image description here

Marijn
  • 37,699