[英]Loop with .each method on ruby
I have a doubt, i have a .each loop like this: 我有一个疑问,我有一个.each循环是这样的:
mayor = @lt[1][1]
@lt.each do |item|
if item[1] > mayor then
mayor = item[1]
end
end
That loop started in the first item of the array @lt
but instead i want it to start by the second item 该循环从数组@lt
的第一项开始,但我希望它从第二项开始
@lt[1..-1].each do |item|
# Do things with item
end
@lt[1..(@lt.length-1)].each { |item|
# Do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.