亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

ruby中的for in與each do的區(qū)別到底是什么?
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-04-21 10:56:48
0
4
917

如果僅像某些文章說的前者的效率不如后者,那要前者做什么?

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證0級(jí)講師

reply all(4)
Ty80

Under normal circumstances, try to use each:

1.upto(10).each { |i| puts i }
puts i # NameError: i is undefined

When using for:

for i in 1.upto(10) do
  puts i
end
puts i # print 10
阿神

It seems there is no difference, there are usually multiple ways to do one thing in ruby

劉奇

each do is more efficient. Some programming standards generally do not recommend using for in

洪濤

This is a matter of programming style. The each loop is a functional style, and the for loop is an imperative style
each is actually a method on an iterable object, accepting a block as a parameter
for is a loop structure implemented in the grammar

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template