当前位置:网站首页>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;
}
边栏推荐
- Introduction, use and principle of synchronized
- Construction of operation and maintenance system
- Dataframe returns the whole row according to the value
- Kubernetes - yaml file interpretation
- Final review points of human-computer interaction
- C language brush questions ~leetcode and simple questions of niuke.com
- Markdown file titles are all reduced by one level
- Idea does not specify an output path for the module
- 驱动与应用程序通信
- GCC cannot find the library file after specifying the link library path
猜你喜欢
视觉上位系统设计开发(halcon-winform)-1.流程节点设计
【可能是全中文网最全】pushgateway入门笔记
视觉上位系统设计开发(halcon-winform)-4.通信管理
Construction of operation and maintenance system
Popular understanding of random forest
Detailed explanation of string function and string function with unlimited length
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team
What is machine reading comprehension? What are the applications? Finally someone made it clear
Visual upper system design and development (Halcon WinForm) -4 Communication management
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
随机推荐
Puppet自动化运维排错案例
Second kill system 3 - list of items and item details
详解指针进阶2
VS2017通过IP调试驱动(双机调试)
Popular understanding of decision tree ID3
C language brush questions ~leetcode and simple questions of niuke.com
Nppexec get process return code
Tensorflow realizes verification code recognition (III)
Relationship between truncated random distribution and original distribution
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
[cloud native training camp] module VIII kubernetes life cycle management and service discovery
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
Jvm-04-runtime data area heap, method area
Puppet automatic operation and maintenance troubleshooting cases
Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
视觉上位系统设计开发(halcon-winform)-6.节点与宫格
视觉上位系统设计开发(halcon-winform)-1.流程节点设计
How to use annotations such as @notnull to verify and handle global exceptions
PyTorch crop images differentiablly