wea*_*ish 2 ruby python loops if-statement break
在Python中,除非循环中断,否则将执行else块:
for person in people:
if is_a_coder(person): break
# ... more code ...
else: # nobreak
print('There is no coder.')
Run Code Online (Sandbox Code Playgroud)
我怎么能在Ruby中做到这一点?
只需使用and
:
people.each do |person|
break if is_a_coder(person)
# more code
end and puts 'There is no coder.'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
92 次 |
最近记录: |