We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
while 循环比 for 循环的自由度更高。在 while 循环中,我们可以自由地设计条件变量的初始化和更新步骤。
例如在以下代码中,条件变量 。每轮进行两次更新,这种情况就不太方便用 for 循环实现:
i每轮进行值的双倍更新,用for循环不是更规范直接嘛?while确实灵活度更高,但是举一个条件变化更为灵活的示例是不是更好一些呢,也更有助于初学者进行理解使用
The text was updated successfully, but these errors were encountered:
请问你指的是哪一页哪里的文字?方便我也看看(发个URL)
Sorry, something went wrong.
Hi,书中的示例对 i 进行了“两次更新”而非仅“双倍更新”,即:
i
while i <= n: res += i # 更新条件变量 i += 1 i *= 2
我们还可以对示例稍作拓展,更加体现 while 的灵活性:
while i <= n: i += 1 res += i i *= 2 res *= i
No branches or pull requests
while 循环比 for 循环的自由度更高。在 while 循环中,我们可以自由地设计条件变量的初始化和更新步骤。
例如在以下代码中,条件变量 。每轮进行两次更新,这种情况就不太方便用 for 循环实现:
i每轮进行值的双倍更新,用for循环不是更规范直接嘛?while确实灵活度更高,但是举一个条件变化更为灵活的示例是不是更好一些呢,也更有助于初学者进行理解使用
The text was updated successfully, but these errors were encountered: