ruby中的循环语句总结
ruby中的循环语句总结
发布时间:2016-12-28 来源:查字典编辑
摘要:while(当…)循环while条件语句1;语句2;语句…end单行while循环(语句1;语句2;语句…)while条件until(直到…...

while(当…) 循环

while条件

语句1;语句2 ;语句…

end

单行while循环

( 语句1;语句2 ;语句… )while条件

until(直到…) 循环

until条件= while not (条件)

for…in循环

for变量in对象

语句1;语句2 ;语句…

end

break

跳出当层循环

next

忽略本次循环的剩余部分,开始下一次的循环

redo

重新开始循环,还是从这一次开始

retry

重头开始这个循环体

times

3.times { print "Hi!" } #Hi!Hi!Hi!

upto

1.upto(9) {|i| print i if i<7 } #123456

downto

9.downto(1){|i| print i if i<7 } #654321

each

(1..9).each {|i| print i if i<7} #123456

step

0.step(11,3) {|i| print i } #0369

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ruby专题学习
热门ruby专题学习
脚本专栏子分类