Nat*_*lin 3 python for-loop skip range julia
在Python中,我们可以使用for循环迭代并使用skip
参数跳过索引:
max_num, jump = 100, 10
for i in range(0, max_num, jump):
print (i)
Run Code Online (Sandbox Code Playgroud)
通过这样做,我可以通过while循环实现相同的目的:
max_num, jump = 100, 10
i = 0
while i < max_num
print(i)
i+=jump
end
Run Code Online (Sandbox Code Playgroud)
并且i+=jump
在for循环中使用下面显示的相同语法不会跳过索引:
for i in range(0,max_num)
print(i)
i+=jump
end
Run Code Online (Sandbox Code Playgroud)
在for循环中是否可以"跳过"?如果是这样,怎么样?
你可以这样做
max_num, step = 100, 10
for i in 0:step:max_num
println(i)
end
Run Code Online (Sandbox Code Playgroud)
使用range(),您不指定max_num,而是指定所需的迭代次数.如此0:step:max_num
平等range(0, step, max_num/step)
.