如何将此for循环转换为while循环? [英] How do I convert this for loop to a while loop?

查看:198
本文介绍了如何将此for循环转换为while循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

t = 0
for i in range(8):
    t = t + 1
print(t)





My尝试





My attempt

i = 7
while i < 8:
    i = i + 1
    print(i)

推荐答案

没关系。我是个白痴。我现在看到了解决方案。



Nevermind. I was an idiot. I see the solution now.

t = 0
i = -1
while i < 7
t = t + 1
i = i + 1
print(t)


这篇关于如何将此for循环转换为while循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆