我可以在Python中做这样的事吗?Python:有没有类似C的for循环可用?
for (i = 0; i < 10; i++):
if someCondition:
i+=1
print i
我需要能够根据条件跳过一些值
编辑:所有的解决方案至今建议修剪以这种或那种方式的初始范围内,基于一个已知条件。这对我没有用,所以让我解释我想要做什么。
我想手动(即没有getopt的)解析某些CMD行参数,其中每个“关键字”有一定数量的参数,像这样:
for i in range(0,len(argv)):
arg = argv[i]
if arg == '--flag1':
opt1 = argv[i+1]
i+=1
continue
if arg == '--anotherFlag':
optX = argv[i+1]
optY = argv[i+2]
optZ = argv[i+3]
i+=3
continue
...
你究竟在做什么? – SilentGhost 2010-07-28 15:16:32
更新的问题与更多的信息... – 2010-07-28 15:39:49
总是有'while'给你。 – Constantin 2010-07-28 20:36:00