作者:等待1314578 | 来源:互联网 | 2023-05-18 18:19
I'm running a while loop inside of a for loop. The array has a length of 9, and I have double checked the length in the program. The for loop should run for each element in the array, but instead only runs for the first element and ends. The while loop on the other hand also uses the length of the array, and runs as expected. The various 'puts' statements show this when you run the code. Why isn't the for loop running 9 times?
我正在for循环中运行while循环。该数组的长度为9,我已经仔细检查了程序中的长度。 for循环应该为数组中的每个元素运行,而是仅针对第一个元素运行并结束。另一方面,while循环也使用数组的长度,并按预期运行。运行代码时,各种'puts'语句会显示这一点。为什么for循环不运行9次?
def stock_picker(stock_prices)
differences = Array.new
stock_prices.each do |price|
day = 0
puts "The for loop is starting"
while day
1 个解决方案