等同于“继续".在Ruby中 [英] Equivalent of "continue" in Ruby

查看:89
本文介绍了等同于“继续".在Ruby中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言和许多其他语言中,有一个continue关键字,当在循环内使用时,跳转到循环的下一个迭代. Ruby中的continue关键字是否等效?

In C and many other languages, there is a continue keyword that, when used inside of a loop, jumps to the next iteration of the loop. Is there any equivalent of this continue keyword in Ruby?

推荐答案

是的,它称为next.

for i in 0..5
   if i < 2
     next
   end
   puts "Value of local variable is #{i}"
end

这将输出以下内容:

Value of local variable is 2
Value of local variable is 3
Value of local variable is 4
Value of local variable is 5
 => 0..5 

这篇关于等同于“继续".在Ruby中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆