Why do these two MWEs produce different effects?
\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\def\aeloaded{Not loaded}
\def\aechanged{Not changed}
\patchcmd{\l@section}
{#1\nobreak\hfil}
{#1\nobreak
\xleaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{--}\mkern \@dotsep
mu$}
\hfil}
{\def\aechanged{Yes}}
{\def\aechanged{No}}%
\def\aeloaded{LOADED}
\makeatother
\pagestyle{empty}
\begin{document}
\begin{tabular}{ll}
Did \verb=article.cls= load? & \aeloaded \\
Did \verb=\patchcmd= work? & \aechanged
\end{tabular}
\end{document}
which generates:

But,
\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\def\aeloaded{Not loaded}
\def\aechanged{Not changed}
\@ifclassloaded{article}
{\patchcmd{\l@section}
{#1\nobreak\hfil}
{#1\nobreak
\xleaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{--}\mkern \@dotsep
mu$}
\hfil}
{\def\aechanged{Yes}}
{\def\aechanged{No}}%
\def\aeloaded{LOADED}
}{\def\aeloaded{load FAILED}}
\makeatother
\pagestyle{empty}
\begin{document}
\begin{tabular}{ll}
Did \verb=article.cls= load? & \aeloaded \\
Did \verb=\patchcmd= work? & \aechanged
\end{tabular}
\end{document}
generates:

\tracingpatchesin the preamble andetoolboxdebugs the patching process to the log. Removing#1from the input will work in this case,\nobreak\hfilonly appears once in the definition of\l@sectionanyway. Using a conditional in\@ifclassloadedand then using that conditional for\patchcmddoes work. – Qrrbrbirlbel Jun 19 '13 at 01:43