# Alternate row colors (shade rows) in algorithmic environment?

In a tabular environment, one can achieve an alternating color of rows by using the rowcolors command like so:

\documentclass[11pt,a4paper]{article}
\usepackage[table]{xcolor}

\begin{document}
\rowcolors{2}{gray!25}{white}
\begin{tabular}{cc}
\rowcolor{gray!50}
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values
\end{tabular}
\end{document}


This will produce:

How can I have a similar effect inside the algorithmic environment? I'm using the algorithmicx package.

EDIT: A MWE of a how I use algorithmicx follows.

\documentclass[a4paper]{article}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1] % [1] provides numbers in every line
\If {$i\geq maxval$}
\State $i\gets 0$
\Else
\If {$i+k\leq maxval$}
\State $i\gets i+k$
\EndIf
\EndIf
\end{algorithmic}
\caption{My algorithm}
\end{algorithm}
\end{document}


This yields:

-
– karlkoeller Aug 14 '13 at 6:36
@karlkoeller I saw that, I was hoping for something less involved, as I don't want to use color on specific rows, only to alternate it.. – geo909 Aug 14 '13 at 7:55
@karlkoeller That question and its answers are quite different, actually. – geo909 Aug 14 '13 at 8:00

\documentclass[a4paper]{article}
\usepackage{color}
\usepackage{algorithm}
\usepackage{algpseudocode}

\renewcommand\alglinenumber[1]%
{\ifodd\value{ALG@line}\relax
\fi
\arabic{ALG@line}}

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1] % [1] provides numbers in every line
\If {$i\geq maxval$}
\State $i\gets 0$
\Else
\If {$i+k\leq maxval$}
\State $i\gets i+k$
\EndIf
\EndIf
\end{algorithmic}
\caption{My algorithm}
\end{algorithm}
\end{document}

-
\footnotesize\arabic{ALG@line}: is more appropriate than \arabic{ALG@line} – karlkoeller Aug 23 '13 at 11:16
@karlkoeller er yes. – David Carlisle Aug 23 '13 at 11:32