\documentclass{article}

\usepackage{algpseudocode}
\usepackage[%
  key = val , %
  key = val , %
]{package}

\begin{document}

\newif\ifluatex
\ifluatex
  luatex specific code
\else
  code for other engines
\fi

\def\IfFileExists#1#2#3{%
  \openin\@inputcheck#1 %
  \ifeof\@inputcheck
    #3\relax
  \else
    \read\@inputcheck to \reserved@a
    \ifx\reserved@a\today
      \typeout{#1 found}#2\relax
    \else
      \typeout{BAD: old file \reserved@a (should be \today)}%
      #3\relax
    \fi
  \fi
  \closein\@inputcheck}

\def\filename@simple#1.#2\\{%
  \ifx\\#2\\%
    \let\filename@ext\relax
    \edef\filename@base{#1}%
  \else
    \filename@dots{#1}#2\\%
  \fi}

\ifx\directlua\@undefined
  \def\newwrite {\e@alloc\write
    \chardef{\count17}
    \m@ne\sixt@@n}
\else
  \def\newwrite {\e@alloc\write {%
      \ifnum\allocationnumber=18
        \advance\count17\@ne
        \allocationnumber\count17 %
      \fi
      \global\chardef
    }%
    {\count17}%
    \m@ne
    {128}}
\fi

\gdef\e@ch@ck#1#2#3#4{%
  \ifnum#1<#2\else
    \ifnum#1=#2\relax
      \global#1\@cclvi
      \ifx\count#4\global\advance#1 10 \fi
    \fi
    \ifnum#1<#3\relax
    \else
      \errmessage{No room for a new \string#4}%
    \fi
  \fi
}%

\def\newinsert#1{%
  \@tempswafalse
  \global\advance\insc@unt\m@ne
  \ifnum\count10<\insc@unt
    \ifnum\count11<\insc@unt
      \ifnum\count12<\insc@unt
        \ifnum\count14<\insc@unt
          \@tempswatrue
        \fi\fi\fi\fi
  \if@tempswa
    \allocationnumber\insc@unt
  \else
    \global\advance\insc@unt\@ne
    \extrafloats\@ne
    \@next\@currbox\@freelist
    {%
      \ifnum\@currbox<\e@insert@top
        \allocationnumber\@currbox
      \else
        \ch@ck0\m@ne\insert
      \fi
    }%
    {\ch@ck0\m@ne\insert}%
  \fi
  \global\chardef#1\allocationnumber
  \wlog{\string#1=\string\insert\the\allocationnumber}%
}

\begin{algorithmic}[1]
  \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
    \State $r\gets a\bmod b$
    \While{$r\not=0$}\Comment{We have the answer if r is 0 and what
        about a large comment}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
    \EndWhile\label{euclidendwhile}
    \State \textbf{return} $b$\Comment{The gcd is b}
    \State
    \Statex
  \EndProcedure
\end{algorithmic}

\begin{algorithmic}[1]
  \State $sum\gets 0$
  \For{$i\gets 1, n$}
    \State $sum\gets sum+i$
  \EndFor
\end{algorithmic}

\begin{algorithmic}[1]
  \State $sum\gets 0$
  \State $i\gets 1$
  \While{$i\le n$}
    \State $sum\gets sum+i$
    \State $i\gets i+1$
  \EndWhile
\end{algorithmic}

\begin{algorithmic}[1]
  \If{$quality\ge 9$}
    \State $a\gets perfect$
  \ElsIf{$quality\ge 7$}
    \State $a\gets good$
  \ElsIf{$quality\ge 5$}
    \State $a\gets medium$
  \ElsIf{$quality\ge 3$}
    \State $a\gets bad$
  \Else
    \State $a\gets unusable$
  \EndIf
\end{algorithmic}

\begin{algorithmic}[1]
  \Require $x\ge5$
  \Ensure $x\le-5$
  \Statex
  \While{$x>-5$}
    \State $x\gets x-1$
  \EndWhile
\end{algorithmic}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
