Control                 package:base                 R Documentation

_C_o_n_t_r_o_l _F_l_o_w

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     if(cond) expr
     if(cond) cons.expr  else  alt.expr
     for(var in seq) expr
     while(cond) expr
     repeat expr
     break
     next

_D_e_t_a_i_l_s:

     Note that `expr' and `cons.expr', etc, in the Usage section above
     means an expression in a formal sense.  This is either a simple
     expression or a so called compound expression, usually of the form
     `{ expr1 ; expr2 }'.

     Note that it is a common mistake to forget putting braces (`{ ..
     }') around your statements, e.g. after `if(..)' or `for(....)'.
     For that reason, one (somewhat extreme) attitude of defensive
     programming uses braces always, e.g. for `if' clauses.

_S_e_e _A_l_s_o:

     `Syntax' for the basis R syntax and operators, `Paren' for
     parentheses and braces; further, `ifelse', `switch'.

_E_x_a_m_p_l_e_s:

     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")
     }

