R语言 循环语句、分支语句和中止语句-控制流篇


for 循环

用法

for (n in m) expr 

若n在m中则运行 expr

while 循环

用法

while (condition) expr

当符合condition时运行expr

repeat 循环

用法

repeat expr

持续运行expr。通常配合break中止语句使用,不然将陷入无限循环。

if/else 判断

用法

if (condition1)
    expr1
else if (condition2)
    expr2
else 
    expr3 

当符合condition1时运行expr1,不符合1但符合2时运行expr2,都不符合时运行expr3。

中止语句

用法

break #中止循环退出循环
next #中止当前循环继续循环


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM