\Header{Control}{Control Flow}
\alias{break}{Control}
\alias{else}{Control}
\alias{for}{Control}
\alias{if}{Control}
\alias{next}{Control}
\alias{repeat}{Control}
\alias{while}{Control}
\keyword{programming}{Control}
\keyword{iteration}{Control}
\keyword{logic}{Control}
\begin{Description}\relax
These are the basic control-flow constructs of the \R{} language.  They
function in much the same way as control statements in any algol-like
language.\end{Description}
\begin{Usage}
\begin{verbatim}
if(cond) expr
if(cond) cons.expr  else  alt.expr
for(var in seq) expr
while(cond) expr
repeat expr
break
next
\end{verbatim}
\end{Usage}
\begin{Details}\relax
Note that \code{expr} and \code{cons.expr}, etc, in the Usage section
above means an \emph{expression} in a formal sense.  This is either a
simple expression or a so called \emph{compound expression}, usually
of the form \code{\{ expr1 ; expr2 \}}.

Note that it is a common mistake to forget putting braces (\code{\{ .. \}})
around your statements, e.g. after \code{if(..)} or \code{for(....)}.
For that reason, one (somewhat extreme) attitude of defensive programming
uses braces always, e.g. for \code{if} clauses.\end{Details}
\begin{SeeAlso}\relax
\code{\Link{Syntax}} for the basis \R{} syntax and operators,
\code{\Link{Paren}} for parentheses and braces; further,
\code{\Link{ifelse}}, \code{\Link{switch}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
for(i in 1:5) print(1:i)

for(n in c(2,5,10,20,50)) {
   x <- rnorm(n)
   cat(n,":", sum(x^2),"\n")
}
\end{ExampleCode}
\end{Examples}

