在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
我们有两种方法来做这件事情: 1。for结构 for (var in seq) statement
例如: > for (i in 1:10) print ("Hello") [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello"
将Hello输出了10次 2。while结构 while (cond) statement
例如: > i<-10 > while (i>0) (print("Hello");i<-i-1) Error: unexpected ';' in "while (i>0) (print("Hello");" > while (i>0) {print("Hello");i<-i-1} [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello" [1] "Hello"
将Hello输出了10次,而且我们注意到,print外面是圆括号的时候报错,花括号的时候才能输出结果! |
请发表评论