如何跨过下一次迭代?

how to step over through next iteration?

store_array = list()
test_case = input()
for i in range(int(test_case)) :
    number1 = input()
    number2 = input()
    store_array.append(int(number1))
    store_array.append(int(number2))

j=0
def add(x,y):
    for j in store_array:
        return x + y 
        j=j+1       
print(add(store_array[j],store_array[j+1]))   

到目前为止我做了什么?

测试用例-> 2

2 2个 3个 3

这些值存储在名称 store_array

下的列表中

它执行并打印前两个值 2 2 并显示输出 4

我怎样才能跳到下两个值并打印连续的其他两个输入?

听起来你想向前推进所有其他值。试试这个,看看是否有帮助。

只需更改:

j=0
def add(x,y):
    for j in store_array:
        return x + y 
        j=j+1  
print(add(store_array[j], store_array[j+1]))  

为此:

def add(x):
    for j in range(0, len(store_array) -1, 2):
        print(x[j] + x[j+1])      

print(add(store_array))  

这可能具有您正在寻找的确切行为,但它是一个很好的起点。

考虑 "continue" 语句。 它使循环跳过一些迭代。

for i in range(6):
    if i % 2 == 0:
        continue
    print(i)

它将跳过所有偶数。