\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}
Asked
Active
Viewed 201 times
0
Su__
- 1
- 1
1 Answers
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:
Marijn
- 37,699


\documentclass, includes all relevant\usepackagecommands, ends with\end{document}and compiles without errors, even if it does not produce your desired output. – Sandy G Mar 23 '22 at 17:35=0at the end, which points to you mixing the use ofalgorithmic(from thealgorithmsbundle) andalgorithmic(fromalgorithmicx). See Algoritmic return command = 0. – Werner Mar 23 '22 at 20:47