[英]How to return the value of a while loop counter
I want to return the counter of the while loops, i and b after every loop repetition to use in another function. I haven't found anything related to returning these values.我想在每次循环重复后返回 while 循环的计数器 i 和 b 以用于另一个 function。我没有发现任何与返回这些值相关的内容。
def dis(reps, towards, back):
t = 0 # move towards t times
b = 0 # move back b times
i = 0 # repetitions
n = 1 # counts every step
while i < reps:
while t < towards:
do_something()
i += 1
n +=1
while b < back:
do_something()
n += 1
b += 1
t = 0
b = 0
i += 1
I thought of adding another variable like counter_towards and counter_back and add a value each time but that would not fix my problem since I still would have to return these values every rep.我想添加另一个变量,如 counter_towards 和 counter_back 并每次添加一个值,但这不能解决我的问题,因为我仍然必须在每次代表时返回这些值。 Adding the related functions to a class might work aswlel but that would be lot of work and i thought there might be an easy answer to this question.将相关功能添加到 class 可能会工作,但这需要大量工作,我认为这个问题可能有一个简单的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.