In the code below, when I use the \For statement, the code does not compile and gives the message:
! Missing \endcsname inserted.
<to be read again>
\ALG@currentbkock@0
Can you help me get the code to compile? Thanks!
Here is the code:
\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb, amsthm, bm}
\usepackage{commath}
\usepackage{xcolor}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\begin{document}
\begin{algorithm}[H]
\DontPrintSemicolon
% \KwData{Training set $x$}
% $\Delta_{ji}^l := 0$ \tcp*{will be used to compute $\partial x$}
% \tcc{iterate over all training examples}
{\bfseries Input:} {a matrix of training samples $A = [A_{1}, A_{2}...,A_{k} ] \in \mathbb{R}^{m\times n}$ for $k$ classes, a test sample $\mathbf{y}\in \mathbb{R}^{m}$, (and an optional error tolerance $\varepsilon > 0$).}\\
Normalize the columns of $A$ to have unit $\ell^{2}$-norm.\\
Solve the $\ell^{1}$-minimization problem:
\begin{equation}
\hat{\bm{x}}_{1} = \arg \min_{x}\norm{\bm{x}}_{1}\quad \text{subject to}\quad A\bm{x} = \bm{y}
\end{equation}
(Or alternatively, solve
\begin{equation}
\hat{\bm{x}}_{1} = \arg \min_{x}\norm{\bm{x}}_{1}\quad \text{subject to}\quad \norm{A\bm{x} = \bm{y}}_{2}\leqslant \varepsilon).
\end{equation}\\
Compute the residuals $r_{i}(\bm{y}) = \norm{\bm{y} - A \delta_{i} (\hat{\bm{x}}_{1})}_{2}$\\
\For{$i = 1,\ldots,k$.}
\EndFor\\
{\bfseries Output:} identity$(\bm{y}) = \arg \min_{i}r_{i}$
\caption{Sparse Representation-based Classification (SRC)}
\end{algorithm}
\end{document}

algorithm2eprovides both thealgorithmenvironment as well as the syntax macros for writing pseudocode.algpseudocodeprovides only syntax macros. You should use eitheralgorithm2eoralgpseudocode(andalgorithm), but not both. – Werner Apr 23 '16 at 15:17algpseudocodebut the code still does not compile. – Joe Apr 23 '16 at 15:23