当前位置:网站首页>流程控制语句
流程控制语句
2022-07-15 16:26:00 【.Null】
流程控制语句
知识点总结:流程控制语句
一. if...else 语句可以看作有4种形式:
1) if语句
if(布尔表达式){ 如果布尔表达式为true将执行的语句}
2) if...else 语句
if(布尔表达式){ 如果布尔表达式的值为true} else{如果布尔表达式的值为false}
3) if...else if...else语句
格式: if(布尔表达式1){如果布尔表达式1的值为true执行代码}
else if(布尔表达式2){ 如果布尔表达式2的值为true执行代码}
else if(布尔表达式3){如果布尔表达式3的值为true执行代码}
else {如果以上布尔表达式都不为true执行代码}
二.嵌套的 if…else 语句
格式: if(布尔表达式1){如果布尔表达式1的值为true执行代码
if(布尔表达式2){如果布尔表达式2的值为true执行代码}}
三.switch语句
switch case 语句有如下规则:
1)switch 语句中的变量类型可以是: byte、short、int或者 char、enum。从 Java SE 7 开始,
switch 支持字符串 String 类型了,同时 case 标签必须为字符串常量或字面量。
2)switch 语句可以拥有多个 case 语句。每个 case 后面跟一个要比较的值和冒号。
3)case 语句中的值的数据类型必须与变量的数据类型相同,而且只能是常量或者字面常量。
4)当变量的值与 case 语句的值相等时,那么 case 语句之后的语句开始执行,直到 break 语句出现才会跳出 switch 语句。
5)当遇到 break 语句时,switch 语句终止。程序跳转到 switch 语句后面的语句执行。case 语句不必须要包含 break 语句。如果没有 break 语句出现,程序会继续执行下一条 case 语句,直到出现break 语句。
6)switch 语句可以包含一个 default 分支,该分支一般是 switch 语句的最后一个分支(可以在任何位置,但一般在最后一个)。default 在没有 case 语句的值和变量值相等的时候执行。default 分支不需要 break 语句。 switch(表达式) {
case表达式值1:语句块1;
break;
case表达式N:语句块N;
break;default:语句块;}
边栏推荐
- A new UI testing method: visual perception test
- @RequestBody
- Loj#576-「LibreOJ NOI Round #2」签到游戏【线段树】
- leetcode:74. 搜索二维矩阵
- 裁员吵架散摊子, 马斯克:我太难了;狠心开源了一个舆情获取项目;取特征工程跟调参一样简单了?!NeRF大佬直呼卷不动了;前沿论文 | ShowMeAI资讯日报
- Animation and encapsulation (offset, client, scroll series)
- 赋能新工业,制造新未来 | 图扑软件受邀参加厦门工业博览会
- After reading these five reasons, I finally know the reason why FTP was replaced
- Matlab-mex
- canal实现从mysql实时同步数据到es
猜你喜欢
随机推荐
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter to configure the separation of different grouped data poin
【森城市】GIS数据漫谈(四)— 坐标系统
Problems that enterprises need to pay attention to when creating product help centers!
如何将notepad++设置为默认打开方式
flink.14 DataStream模块 source底层是怎么实现的?
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图
函数与Symbol
What is the difference between reject and catch processing in promise
The INI file configuration should be modified during Jerry's mode [chapter]
Symbol数据类型
企业在创建产品帮助中心时需要注意的问题!
杰理之内置触摸可供修改的参数【篇】
CS5801_HDMI转EDP优势替代LT6711A方案
Function advanced application
图扑 Web 可视化引擎在仿真分析领域的应用
Jerry's n turns on the 1-2 function, which will affect the Bluetooth distance [article]
G1这么强,你确定不了解一下?
R language ggplot2 visualization: use the ggboxplot function of ggpubr package to visualize the box graph, set the add parameter to add the distribution data point graph (dot plot, dot plot) to the bo
Web开发人员的10个数据库优化最佳实践
Network socket programming









