R中的循环:
> for (i in 1:3){
+ cat(i, "+", 1, "=", i+1, "\n")
+ }
1 + 1 = 2
2 + 1 = 3
3 + 1 = 4被遍历的序列除了整数向量外,还包括列表、数据帧、矩阵。
控制流:if和if else语句
> for (i in 1:3){
+ if(i==2) cat("The index is 2", "\n") else
+ cat("The index is not 2", "\n")
+ }
The index is not 2
The index is 2
The index is not 2while循环: while (条件判断) 表达式
repeat循环: repeat表达式
repeat循环需要手动跳出。break跳出循环,next停止当前迭代,直接转向下一次迭代。

for循环函数
"\n"换行符
cat()循环变元
if语句和if else 语句的区别
repeat 和 while 循环的流向图
while 和 repeat 循环
循环语句之 for循环, cat()函数的使用:参数会被连接到一起,并和结果一起打印出来。