ruby - 使用用户输入中断 while 循环
问题描述
我如何通过用户输入打破循环 除了是之外的示例输入只会让我打破循环 在此处输入图像描述
解决方案
def main
loop do
# ...
puts "Repeat for another input?"
ans = gets.chomp
if ans != "yes"
break # will break the loop
end
end
end
main
推荐阅读
- python - Create graph from dicts python
- visual-studio-code - 用于 Vs 代码的 Julia 自动完成的更好插件
- java - Spring Data Specification Join by specific field
- php - 处理对象数组时如何避免循环中的array_merge
- swift - 数据包隧道提供商 IOS 中的动态 DNS
- angular - 如何使用保存在数据库中的路径从 .net core web api wwwroot 文件夹中获取图像
- asp.net - 如何销毁 pre cookie 值
- google-apps-script - 正确使用 getRange 和 getLastRow 作为源和目标范围
- c++ - 名称查找、实例化点 (POI) 和基本类型
- angular - router.config 没有所有应用程序路由