Here's one possible solution using (oh, surprise!) the improved version of \tikzmark provided by Andrew Stacey in his answer to tikzmark to have different behaviour if first run (and mark locations not yet available).
The idea is to define a new family of loops and declarations, totally analogous to the ones provided by algcompatible, but adding automatically the colored background; for each command of the form \X now you have the corresponding command \CX (prepending a capital C to the original name) which automatically handles the color; for example, now you have the standard \STATE command and the colored version \CSTATE; the functionality and syntax of each \CX command is exactly the same as that of its corresponding \X command.
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass{beamer}
\usepackage[dvipsnames]{xcolor}
\usepackage{algcompatible}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
% code borrowed from Andrew Stacey; See
% https://tex.stackexchange.com/a/50054/3954
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
\makeatother
% end of Andrew's code
% main command to draw the colored background
\newcounter{mymark}
\newcommand\ColorLine{%
\stepcounter{mymark}%
\tikz[remember picture with id=mark-\themymark,overlay] {;}%
\begin{tikzpicture}[remember picture,overlay]%
\filldraw[GreenYellow]%
let \p1=(pic cs:mark-\themymark),
\p2=(current page.east) in
([xshift=-0.3em,yshift=-0.7ex]0,\y1) rectangle ++([xshift=-1.2cm]\x2,\baselineskip);
\end{tikzpicture}%
}%
% colored loops and declarations
\makeatletter
\algnewcommand\CREQUIRE{\item[\ColorLine\algorithmicrequire]}%
\algnewcommand\CENSURE{\item[\ColorLine\algorithmicensure]}%
\algnewcommand\CSTATE{\State\ColorLine}%
\algnewcommand\CSTATEx{\Statex\ColorLine}%
\algnewcommand\CCOMMENT{\Comment\ColorLine}%
\algdef{SE}[WHILE]{CWHILE}{ENDWHILE}%
[2][default]{\ColorLine\algorithmicwhile\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicwhile}%
\algdef{SE}[FOR]{CFOR}{ENDFOR}%
[2][default]{\ColorLine\algorithmicfor\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicfor}%
\algdef{S}[FOR]{CFORALL}%
[2][default]{\ColorLine\algorithmicforall\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
\algdef{SE}[LOOP]{CLOOP}{ENDLOOP}%
[1][default]{\ColorLine\algorithmicloop\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicloop}%
\algdef{SE}[REPEAT]{CREPEAT}{UNTIL}%
[1][default]{\ColorLine\algorithmicrepeat\ALG@compatcomm{#1}}%
[1]{\algorithmicuntil\ #1}%
\algdef{SE}[IF]{CIF}{ENDIF}%
[2][default]{\ColorLine\algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicif}%
\algdef{C}[IF]{IF}{CELSIF}%
[2][default]{\ColorLine\algorithmicelse\ \algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
\algdef{Ce}[ELSE]{IF}{CELSE}{ENDIF}%
[1][default]{\ColorLine\algorithmicelse\ALG@compatcomm{#1}}%
\makeatother
\begin{document}
\begin{frame}{Test Frame 1}
\begin{algorithmic}[1]
\CREQUIRE Some initial values
\ENSURE Some conditions
\CLOOP
\STATE$bar(elem)$
\STATE$baz(elem)$
\CFOR{$quality\ge 9$}
\STATE$a\gets perfect$
\CSTATE$a\gets unusable$
\ENDFOR
\ENDLOOP
\end{algorithmic}
\end{frame}
\begin{frame}{Test Frame 2}
\begin{algorithmic}[1]
\REQUIRE Some initial values
\CENSURE Some conditions
\FORALL{$elem$ in $collection$}
\STATE$bar(elem)$
\CSTATE$foo(elem)$
\STATE$baz(elem)$
\CIF{$quality\ge 9$}
\STATE$a\gets perfect$
\ELSE
\CSTATE$a\gets unusable$
\ENDIF
\ENDFOR
\end{algorithmic}
\end{frame}
\end{document}
The images of the obtained document:


The document has to be processed twice.
And here's a little variation in which the background colored stripes have uniform length:
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass{beamer}
\usepackage[dvipsnames]{xcolor}
\usepackage{algcompatible}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
% code borrowed from Andrew Stacey; See
% https://tex.stackexchange.com/a/50054/3954
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
% end of Andrew's code
\newlength\AlgIndent
\setlength\AlgIndent{0pt}
% main command to draw the colored background
\newcounter{mymark}
\newcommand\ColorLine{%
\stepcounter{mymark}%
\tikz[remember picture with id=mark-\themymark,overlay] {;}%
\begin{tikzpicture}[remember picture,overlay]%
\filldraw[GreenYellow]%
let \p1=(pic cs:mark-\themymark),
\p2=(current page.east) in
([xshift=-\ALG@thistlm-0.3em,yshift=-0.7ex]0,\y1) rectangle ++(\linewidth+\AlgIndent,\baselineskip);
\end{tikzpicture}%
}%
% colored loops and declarations
\algnewcommand\CREQUIRE{\item[\setlength\AlgIndent{1.6em}\ColorLine\algorithmicrequire]}%
\algnewcommand\CENSURE{\item[\setlength\AlgIndent{1.6em}\ColorLine\algorithmicensure]}%
\algnewcommand\CSTATE{\State\ColorLine}%
\algnewcommand\CSTATEx{\Statex\ColorLine}%
\algnewcommand\CCOMMENT{\Comment\ColorLine}%
\algdef{SE}[WHILE]{CWHILE}{ENDWHILE}%
[2][default]{\ColorLine\algorithmicwhile\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicwhile}%
\algdef{SE}[FOR]{CFOR}{ENDFOR}%
[2][default]{\ColorLine\algorithmicfor\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicfor}%
\algdef{S}[FOR]{CFORALL}%
[2][default]{\ColorLine\algorithmicforall\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
\algdef{SE}[LOOP]{CLOOP}{ENDLOOP}%
[1][default]{\ColorLine\algorithmicloop\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicloop}%
\algdef{SE}[REPEAT]{CREPEAT}{UNTIL}%
[1][default]{\ColorLine\algorithmicrepeat\ALG@compatcomm{#1}}%
[1]{\algorithmicuntil\ #1}%
\algdef{SE}[IF]{CIF}{ENDIF}%
[2][default]{\ColorLine\algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
{\algorithmicend\ \algorithmicif}%
\algdef{C}[IF]{IF}{CELSIF}%
[2][default]{\ColorLine\algorithmicelse\ \algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
\algdef{Ce}[ELSE]{IF}{CELSE}{ENDIF}%
[1][default]{\ColorLine\algorithmicelse\ALG@compatcomm{#1}}%
\makeatother
\begin{document}
\begin{frame}{Test Frame 1}
\begin{algorithmic}[1]
\CREQUIRE Some initial values
\ENSURE Some conditions
\CLOOP
\STATE$bar(elem)$
\STATE$baz(elem)$
\CFOR{$quality\ge 9$}
\STATE$a\gets perfect$
\CSTATE$a\gets unusable$
\ENDFOR
\ENDLOOP
\end{algorithmic}
\end{frame}
\begin{frame}{Test Frame 2}
\begin{algorithmic}[1]
\REQUIRE Some initial values
\CENSURE Some conditions
\FORALL{$elem$ in $collection$}
\STATE$bar(elem)$
\CSTATE$foo(elem)$
\STATE$baz(elem)$
\CIF{$quality\ge 9$}
\STATE$a\gets perfect$
\ELSE
\CSTATE$a\gets unusable$
\ENDIF
\ENDFOR
\end{algorithmic}
\end{frame}
\end{document}


end forhas not too much information, but it could be useful sometimes. I was thinking to add a new definition such as:\algdef{SE}[FOR]{CFOR}{CENDFOR}% [2][default]{\ColorLine\algorithmicfor\ #2\ \algorithmicdo\ALG@compatcomm{#1}}% {\ColorLine\algorithmicend\ \algorithmicfor}%. Would that be the correct way to implement coloring forend for? – betabandido Jul 26 '12 at 09:02\State$a$\gets$\max_x f(x)$, where the subscript extends below the "normal" height of the line? Other than that it works great! – 3lectrologos Mar 20 '13 at 19:29\CSTATE$a\gets\max_x f(x)$and the colored stripe covers the text with no problems; if you are experiencing something different, please open a fresh new question as a follow-up questions to this one; don't forget to add a MWE to the new question, allowing us to replicate the problem. – Gonzalo Medina Mar 20 '13 at 20:55