Actions
Bug #13802
closedbreak inside loop is not working as expected
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
Description
Reproduce process:
- Create a file (.rb)
- Add the below code
- Run with syntax - ruby .rb
your ruby version (ruby -v):
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
reproducible ruby script:
y=1
loop do
y += 1
next unless y%2==0
puts y
break if y > 10
end
Result of reproduce process:
2
4
6
8
10
12
[Finished in 0.0s]
Expected result and the reason why you expect:
2
4
6
8
10
[Finished in 0.0s]
Reason is when the condition "y > 10" is met, the code should exit from there, tested with both "break" and "exit". result is same.
Files
Actions
Like0
Like0Like0Like0