当前位置:网站首页>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;
}边栏推荐
- 阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
- [transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
- Popular understanding of decision tree ID3
- Finally, someone explained the financial risk management clearly
- Matlab r2011b neural network toolbox precautions
- Jvm-04-runtime data area heap, method area
- What is label encoding? How to distinguish and use one hot encoding and label encoding?
- 开启 Chrome 和 Edge 浏览器多线程下载
- 在MapReduce中利用MultipleOutputs输出多个文件
- Detailed explanation of string function and string function with unlimited length
猜你喜欢

Kubernetes advanced training camp pod Foundation

Finally, someone explained the financial risk management clearly

详解指针进阶1
![Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)](/img/cd/2e4f5884d034ff704809f476bda288.png)
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)

软件逆向破解入门系列(1)—xdbg32/64的常见配置及功能窗口

Popular understanding of random forest

Reentrantlock usage and source code analysis

Popular understanding of gradient descent

【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现

C语言刷题~Leetcode与牛客网简单题
随机推荐
Idea does not specify an output path for the module
do{}while()的妙用
运维体系的构建
需要知道的字符串函数
C language brush questions ~leetcode and simple questions of niuke.com
秒杀系统2-Redis解决分布式Session问题
Puppet automatic operation and maintenance troubleshooting cases
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
Apache ant extension tutorial
Popular understanding of gradient descent
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
Tensorflow realizes verification code recognition (III)
Visual upper system design and development (Halcon WinForm) -2 Global variable design
Jvm-08-garbage collector
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
Construction of operation and maintenance system
Seckill system 3- product list and product details
redis单线程问题强制梳理门外汉扫盲
CString的GetBuffer和ReleaseBuffer使用说明