if条件语句:if (conditon) {expr1} else {expr2}spa
> x<-1
> if(x==1)
+ {x<-"x=1"}else
+ {x<-"x!=1"}
> x
[1] "x=1"it
注意:else不能单独做为一行io
循环语句循环
距离:计算从1到30的和di
for语句:for (n in x) {expr}while
> x<-0
> for(i in 1:30)
+ {x=x+i}
> x
[1] 465co
while语句:while (condition) {expr}
> x<-0> i<-1> while(i<=30)+ {x=x+i+ i=i+1+ }> x[1] 465