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?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- es 单字段多分词器时,textField.keyword无法高亮
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
Yes, it's called
next
.This outputs the following:
Ruby has two other loop/iteration control keywords:
redo
andretry
. Read more about them, and the difference between them, at Ruby QuickTips.I think it is called next.
next
also, look at
redo
which redoes the current iteration.Writing Ian Purton's answer in a slightly more idiomatic way:
Prints:
Inside for-loops and iterator methods like
each
andmap
thenext
keyword in ruby will have the effect of jumping to the next iteration of the loop (same ascontinue
in C).However what it actually does is just to return from the current block. So you can use it with any method that takes a block - even if it has nothing to do with iteration.