python - Python中的循环循环
问题描述
我想知道您是否可以在循环 B 中时在 python 中重新启动循环 A。例如:
while True: #Loop A
while True: #Loop B
ans = int("Question")
if ans == "y":
print("Something")
else:
???
和 ???代表代码返回并重复循环A。拜托,我真的需要这个答案。对于那些已经或将要回答的人,谢谢!
解决方案
在python中,您可以使用break
退出您所在的循环。
while True: #Loop A
while True: #Loop B
ans = int("Question")
if ans == "y":
print("Something")
else:
break
推荐阅读
- android - 如何在没有 AccountManager 或权限的情况下在 EditText 上显示用户电子邮件
- c# - 在 DataGridView 中动态填充 ComboBox 列
- objective-c - 自定义 NSMenu 项目标题在 Cocoa 应用程序中可见
- android - 如何在视图位于另一个视图之上的情况下实现这种布局设计
- android - com.google.firebase:firebase-database:11.4.2
- php - 在 Symfony 中显示实体?
- ruby-on-rails - 为不同环境配置带有 Rails 的 Neo4j
- sql - 使用多个表时的 SUM 函数无法正常工作
- php - 添加外键时Laravel迁移错误
- ios - AKMicrophone 导致 SIGABRT 错误 - 一个错误?