用while(true)和continue、break来实现在一个大循环里switch
来源:互联网 发布:表格算量软件 编辑:程序博客网 时间:2024/04/29 14:53
while (true) { System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书"); String book; try { //取得整型命令 int command = inputCommand(); //根据不同命令值,进行不同操作 switch (command) { case 1://按照图书名称选择图书 book = getBookByName(books); System.out.println("book:" + book); break; case 2://按照图书序号(数组下标)选择图书 book = getBookByNumber(books); System.out.println("book:" + book); break; case -1://返回值为-1,说明输入有误 System.out.println("命令输入错误!请根据提示输入数字命令!"); continue; default://其他值的命令均认为是错误命令 System.out.println("命令输入错误!"); continue; } break;//退出程序 } catch (Exception bne) { //捕获”图书不存在异常“时,要求重新输入命令 System.out.println(bne.getMessage()); continue; } }
值得学习:
用while(true)和continue、break来实现在一个大循环里switch:
如果是选择了需要的“1”就break,如果是其他的(-1或者deafult)就用continue来反复循环,直到用户输入正确。
0 0
- 用while(true)和continue、break来实现在一个大循环里switch
- 用while(true)和continue、break来实现在一个大循环里switch
- continue、break 和 switch
- Python的while语句(continue,break,True)
- 3.[do...while]+[switch]+[break]+[continue]
- switch,for,while,break,continue语句
- switch/for/while/break/continue的使用
- switch 中的 break 和continue
- break continue 在 for循环和 switch 的 不同
- for,while,do...while,switch,break,continue,return的用法
- switch在循环中时 可以用continue替代break
- break和continue在switch中,在循环中以及在循环中的switch的区别
- break和continue在switch中,在循环中以及在循环中的switch的区别
- jQeruy 里each循环中的break与continue的替代物return false;和return true;
- php break,for,while,dowhile,switch,continue,goto,常量
- java的选择结构switch和循环结构for while do while以及流程控制语句break continue return
- Jquery的each里用return true或false代替break或continue
- for while的continue和break
- Deep learning:四十八(Contractive AutoEncoder简单理解)
- ROS基础学习笔记——工作空间、CMakeList、package.xml
- 二叉树的链式存储结构 前序 后序 中序 层序遍历操作实现 判断是否完全二叉树
- 一些Android Demo的网址
- 第三周项目-换分币
- 用while(true)和continue、break来实现在一个大循环里switch
- 地图上绘制多边形
- 采样技术
- Linux下软连接的概念
- Scala学习笔记--第4章 Scala数组
- 使用openframeworks无需配置学习新版本opengl
- 通过VPS SSH隧道使用本地msf
- 【Leetcode】之Find Minimum in Rotated Sorted Array
- Linux 解决Sublime无法输入中文