当前位置:网站首页>Branch if statement
Branch if statement
2022-04-21 11:47:00 【wx6235761444879】
What is a sentence ?
int
a
=
0;
// A piece of code separated by English semicolons is a statement
;
// Empty statement
1
+
2;
- 1.
- 2.
- 3.
that if What is the structure of the statement ?
1.
if(
expression )
sentence ;
2.
if(
expression )
sentence ;
else
sentence ;
3.
if(
expression 1)
sentence ;
else
if(
expression 2)
sentence ;
else
sentence ;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
Look at the infrastructure , Let's write a piece of code !
int
main()
{
if(
age
<
18)
{
printf(
" A minor \n");
}
else
if(
age
>=
18
&&
age
<=
30)
//&& Show and
printf(
" adult \n");
else
if(
age
>
30
&&
age
<=
60)
printf(
" middle-aged \n");
else
printf(
" The elderly \n");
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
The above code is in the form of structure three , So it's also possible to use structure 2 to write here
int
main()
{
if(
age
<
18)
{
printf(
" A minor \n");
}
else
{
if(
age
>=
18
&&
age
<=
30)
//&& Show and
printf(
" adult \n");
else
if(
age
>
30
&&
age
<=
60)
printf(
" middle-aged \n");
else
printf(
" The elderly \n");
}
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
Here's the point ,else How does this keyword work ? Now let's talk about hanging else To understand the else Operation of
int
main()
{
int
a
=
0;
int
b
=
2;
if(
a
==
1)
//== Said judgment
{
if(
b
==
2)
{
printf(
"hehe\n");
}
}
else
printf(
"haha\n");
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
Guess what the code output is ?
The output is nothing
Then why is this ?
The reason is simple , Don't think so complicated . The reason is that else And recent if matching
Come on , Let's see how the code works

We Understand the hanging else , So how to modify this code ?
int
main()
{
int
a
=
0;
int
b
=
2;
if(
a
==
1)
{
if(
b
==
2)
printf(
"hehe\n");
else
printf(
"haha\n");
}
return
0;
}
// Of course, the result is nothing When we get here, we understand that hanging in the air else
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
summary :
In the air else It's with the latest if Match
Here are some questions
int
main()
{
int
sum
=
4;
if(
sum
=
5)
printf(
"hehe\n");
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
Let's think about the result first
The result is hehe
Do you really know this code ?( As a beginner , I was wrong at a glance )
Let me talk about how this code works

Be careful : Symbol = Indicates assignment , It's not judgment
Now let's look at another topic
Print out 1-100 All the odd numbers of
int
main()
{
int
i
=
1;
while(
i
<=
100)
//while Represents a cycle
{
if(
i
%
2
==
1)
//% Representation module
{
printf(
"%d ",
i);
}
i
++;
}
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
here while Represents a cycle
This code is not hard , Simple . Come on , go

You can also write like this
int
main()
{
int
i
=
1;
while(
i
<=
100)
{
printf(
"%d ",
i);
i
+=
2;
//i+=2 Namely i=i+2;
}
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
This is it. if Branch , Simple understanding , Deep absorption
The point is to hang in the air else And some key symbols
Thank you for watching. !
版权声明
本文为[wx6235761444879]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211109376722.html
边栏推荐
- MQ相關流程及各項內容
- 基于SSM开发的医院住院管理信息系统(HIMS)-毕业设计-附源码
- ASP dotnet core does integration test based on TestServer
- Forward port 80 requests to other ports
- Solution | fast intercom dispatching system: efficient cooperation
- 飞控中的IIR二阶滤波器
- IDEA的LeetCode力扣插件设置
- 会声会影2022发布会声会影2022的8项全新功能介绍(官方)
- Dapr 远程调试之 Nocalhost
- L2-003 月饼 (25 分)(贪心)
猜你喜欢

离线强化学习(Offline RL)系列4:(数据集) 经验样本复杂度(Sample Complexity)对模型收敛的影响分析

Filter

stm32i2c的解答

ASP. Net core to realize JWT authorization and authentication (1. Theory)

连接服务器报错No supported authentication methods available

# yyds干货盘点 # 盘点一个网络爬虫中常见的一个错误

leaflet军事标绘-突击方向修改(leaflet篇.90)

路由基础之控制RIP路由的发布及路由引入
![[high quality original] share some unknown and super easy-to-use API functions in sklearn module](/img/7c/5663e808d96ab38397d09226121187.png)
[high quality original] share some unknown and super easy-to-use API functions in sklearn module

解决方案| 快对讲调度系统:高效协作
随机推荐
Conversion between localdate, localdatetime and date
L2-001 紧急救援 (25 分)(dijkstra综合应用)
分支 if语句
【招聘测评题】中的(行测)图形推理题基本逻辑总结(附例题)
1.精准营销实践阿里云odpscmd精准营销数据处理
文件传输(上传下载)
基于SSM开发的医院住院管理信息系统(HIMS)-毕业设计-附源码
InfoQ 入驻快讯
File transfer (upload and download)
Basic logic summary of (line test) graphic reasoning questions in [recruitment evaluation questions] (with examples)
Dapr 远程调试之 Nocalhost
Path theme -- difference between server and browser
pycharm中归一化记录
Offline RL Series 4: analysis of the influence of sample complexity on model convergence
路径专题--服务器与浏览器区别
No supported authentication methods available
离线强化学习(Offline RL)系列4:(数据集) 经验样本复杂度(Sample Complexity)对模型收敛的影响分析
Decorator modifier / binary array of ES6 new feature (8)
华为、海尔智家、小米都在做的全屋智能,全在哪?
【C语言实现通讯录】一文带你遍历C语言重难点