Last active
December 2, 2018 14:09
-
-
Save ktanaka101/8fa103e3121aaefd18813a4f6823e96a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# crystal | |
# https://crystal-lang.org/docs/syntax_and_semantics/blocks_and_procs.html | |
arr = [1, 2, 3, 4, 5] | |
def b(arr) | |
loop do | |
arr.each do |x| | |
yield x | |
end | |
end | |
end | |
b(arr) do |x| | |
break if x == 3 | |
end | |
p "End" # => "End" | |
def c(arr) | |
arr.each do |x| | |
yield x | |
end | |
end | |
c(arr) do |x| | |
break if x == 3 | |
end | |
p "End" # => "End" | |
def d(arr) | |
loop do | |
loop do | |
arr.each do |x| | |
yield x | |
end | |
end | |
end | |
end | |
d(arr) do |x| | |
break if x == 3 | |
end | |
p "End" # => End | |
def e(arr) | |
i = 0 | |
loop do | |
arr.each do |x| | |
break | |
end | |
i = i + 1 | |
return false if i == 2 | |
end | |
true | |
end | |
if e(arr) | |
p "End" # No exec | |
else | |
p "loop!!" #=> "loop!!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment