Python 将for循环转换为while循环
如何将这些for循环转换为while循环?您缺少for和while循环的要点 基本上,for循环在列表中迭代,您可以在执行操作时对项目进行操作 相反,while循环用于运行直到满足条件,例如触发标志 for循环: 返回:Python 将for循环转换为while循环,python,Python,如何将这些for循环转换为while循环?您缺少for和while循环的要点 基本上,for循环在列表中迭代,您可以在执行操作时对项目进行操作 相反,while循环用于运行直到满足条件,例如触发标志 for循环: 返回: mylist = ["this", "is", "a", "for", "loop"] for element in mylist: print(element) count = 0 while count != 10: print(count) co
mylist = ["this", "is", "a", "for", "loop"]
for element in mylist:
print(element)
count = 0
while count != 10:
print(count)
count += 1
print("count has reached 10")
其中,作为while循环:
this
is
a
while
loop
返回:
mylist = ["this", "is", "a", "for", "loop"]
for element in mylist:
print(element)
count = 0
while count != 10:
print(count)
count += 1
print("count has reached 10")
总之,for循环用于迭代数组或生成器对象,其中as-while循环用于运行,直到满足条件。为什么要将其转换为while循环?你在使用for循环时遇到了什么问题?while循环与for循环的比较是什么?我只是好奇你会怎么做。我做过其他的转换,但这一次让我很难堪。可能是重复的