当前位置:网站首页>The wonderful use of do{}while()
The wonderful use of do{}while()
2022-07-03 15:26:00 【Yulong_】
Sometimes you often see in code do{}while(0),do{}while(false) This kind of form that looks a little strange , In fact, using this method in the project is very wonderful , It can reduce many problems in functional logic return Or multi-layer nesting if...else... In the form of , It can be easily implemented. There is only one in the function return, See the following code :
#include <stdlib.h>
#include <stdio.h>
// Permission check function
bool DoCheck(int n)
{
bool bRet = false;
do
{
if (n & 0x1)
{
bRet = true;
}
if (n & 0x2)
{
bRet = false;
break;
}
if (n & 0x4)
{
bRet = false;
break;
}
if (n & 0x10)
{
// without do...while In the form of , You may need to directly return Or nested multiple if...else...
bRet = true;
break;
}
if (n & 0x20)
{
bRet = true;
}
if (n & 0x40)
{
bRet = true;
}
} while (false);
return bRet;
}
int main()
{
// Permission to check
if (DoCheck(0x11))
{
printf("yes!\n");
}
else
{
printf("no\n");
}
system("pause");
return 0;
}边栏推荐
- Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
- Jvm-08-garbage collector
- Jvm-05-object, direct memory, string constant pool
- socket.io搭建分布式Web推送服务器
- Tensorflow realizes verification code recognition (II)
- Kubernetes - yaml file interpretation
- The method of parameter estimation of user-defined function in MATLAB
- Summary of JVM knowledge points
- Stress test WebService with JMeter
- String functions that you need to know
猜你喜欢

Final review points of human-computer interaction

Finally, someone explained the financial risk management clearly

子类隐藏父类的同名函数
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes

Second kill system 3 - list of items and item details

Jvm-03-runtime data area PC, stack, local method stack

视觉上位系统设计开发(halcon-winform)-3.图像控件

Summary of JVM knowledge points

Dataframe returns the whole row according to the value

从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
随机推荐
socket. IO build distributed web push server
mysql innodb 存储引擎的特性—行锁剖析
Stress test WebService with JMeter
Visual upper system design and development (Halcon WinForm) -3 Image control
[cloud native training camp] module VIII kubernetes life cycle management and service discovery
互斥对象与临界区的区别
开启 Chrome 和 Edge 浏览器多线程下载
Halcon与Winform学习第一节
Tensorflow realizes verification code recognition (I)
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
redis缓存穿透,缓存击穿,缓存雪崩解决方案
XWiki安装使用技巧
Redis主从、哨兵、集群模式介绍
需要知道的字符串函数
Use of Tex editor
视觉上位系统设计开发(halcon-winform)-6.节点与宫格
VC下Unicode和ANSI互转,CStringW和std::string互转
子类隐藏父类的同名函数
Puppet自动化运维排错案例
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding