You can use
next to try to execute the next iteration of a
while loop. After executing
while's condition is checked and, if truthy, the body will be executed.
a = 1 while a < 5 a += 1 if a == 3 next end puts a end # The above prints the numbers 2, 4 and 5
next can also be used to exit from a block, for example:
def block yield end block do puts "hello" next puts "world" end # The above prints "hello"
next can also take a parameter which will then be returned by
def block puts yield end block do next "hello" end # The above prints "hello"
To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.