当前位置:网站首页>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;
}边栏推荐
- 基于SVN分支开发模式流程浅析
- Solve the problem that pushgateway data will be overwritten by multiple push
- Backtracking method to solve batch job scheduling problem
- [combinatorics] permutation and combination (set permutation, step-by-step processing example)
- Jvm-03-runtime data area PC, stack, local method stack
- QT common sentence notes
- redis单线程问题强制梳理门外汉扫盲
- The difference between RAR and zip files
- Puppet automatic operation and maintenance troubleshooting cases
- Kubernetes - yaml file interpretation
猜你喜欢
![[cloud native training camp] module VIII kubernetes life cycle management and service discovery](/img/87/92638402820b32a15383f19f6f8b91.png)
[cloud native training camp] module VIII kubernetes life cycle management and service discovery

Matplotlib drawing label cannot display Chinese problems

Basic SQL tutorial
![[transform] [NLP] first proposed transformer. The 2017 paper](/img/33/f639ab527d5adedfdc39f8d8117c3e.png)
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team

Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock

【可能是全中文网最全】pushgateway入门笔记

Didi off the shelf! Data security is national security

String functions that you need to know

C语言刷题~Leetcode与牛客网简单题

详解指针进阶2
随机推荐
WinDbg分析dump文件
视觉上位系统设计开发(halcon-winform)-5.相机
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
Digital image processing -- popular Canny edge detection
QT common sentence notes
Popular understanding of linear regression (I)
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
Detailed comments on MapReduce instance code on the official website
CString在多线程中的问题
基础SQL教程
Kubernetes advanced training camp pod Foundation
求字符串函数和长度不受限制的字符串函数的详解
Redis主从、哨兵、集群模式介绍
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
[set theory] inclusion exclusion principle (complex example)
Seckill system 3- product list and product details
Detailed pointer advanced 2
视觉上位系统设计开发(halcon-winform)-3.图像控件
How to use annotations such as @notnull to verify and handle global exceptions
[daily training] 395 Longest substring with at least k repeated characters