\usemodule[algorithmic]

\enableregime[utf]

\showframe

\starttext

\subject{The {\it if-then-else} Statement}

\startalgorithmic
\IF{some condition is true}
\STATE do some processing
\ELSIF{some other condition is true}
\STATE do some different processing
\ELSIF{some even more bizarre condition is met}
\STATE do something else
\ELSE
\STATE do the default actions
\ENDIF
\stopalgorithmic

\subject{The {\it for} Loop}

\startalgorithmic
\FOR{$i=0$ to $10$}
\STATE carry out some processing
\ENDFOR
\stopalgorithmic

\startalgorithmic
\FORALL{$i$ such that $0\leq i\leq 10$}
\STATE carry out some processing
\ENDFOR
\stopalgorithmic

\subject{The {\it while} Loop}

\startalgorithmic
\WHILE{some condition holds}
\STATE carry out some processing
\ENDWHILE
\stopalgorithmic

\subject{The {\it repeat-until} Loop}

\startalgorithmic
\REPEAT
\STATE carry out some processing
\UNTIL{some condition is met}
\stopalgorithmic

\subject{The Inﬁnite Loop}

\startalgorithmic
\LOOP
\STATE this processing will be repeated forever
\ENDLOOP
\stopalgorithmic

\subject{The Precondition}

\startalgorithmic
\REQUIRE $x \neq 0$ and $n \geq 0$
\stopalgorithmic

\subject{The Postcondition}

\startalgorithmic
\ENSURE $x \neq 0$ and $n \geq 0$
\stopalgorithmic

\subject{Returning Values}

\startalgorithmic
\RETURN $(x+y)/2$
\stopalgorithmic

\startalgorithmic
\IF{$n$ is odd}
\RETURN \TRUE
\ELSE
\RETURN \FALSE
\ENDIF
\stopalgorithmic

\subject{Printing Messages}

\startalgorithmic
\PRINT {\tt ‘‘Hello, World!’’}
\stopalgorithmic

\subject{Comments}

\startalgorithmic
\STATE do something \COMMENT{this is a comment}
\stopalgorithmic

\subject{An Example}

\startbuffer
\startalgorithmic[numbering=line]
\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \leftarrow 1$
\IF{$n < 0$}
\STATE $X \leftarrow 1 / x$
\STATE $N \leftarrow -n$
\ELSE
\STATE $X \leftarrow x$
\STATE $N \leftarrow n$
\ENDIF
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \leftarrow X \times X$
\STATE $N \leftarrow N / 2$
\ELSE
\STATE $y \leftarrow y \times X$
\STATE $N \leftarrow N - 1$
\ENDIF
\ENDWHILE
\stopalgorithmic
\stopbuffer

\typebuffer \getbuffer

\stoptext
