当前位置:网站首页>Solid smart contract development - 3.3-solid syntax control structure
Solid smart contract development - 3.3-solid syntax control structure
2022-07-27 07:58:00 【Crypto168】
solidity The control structures of are if, else, while, do, for, break, continue, return. These keywords are in the C Language and JavaScript The expression is the same in , Learn these three axes well, and all the logical structures are easy to realize .
1. if-else
function test(uint256 _number) public pure returns(bool){
if(_number == 0){
return(true);
}else{
return(false);
}
}2. for loop
function test() public pure returns(uint256){
uint sum = 0;
for(uint i = 0; i < 100; i++){
sum += i;
if(sum > 50){
break;
}
}
return(sum);
}3. do-while loop
function test() public pure returns(uint256){
uint sum = 0;
uint i = 0;
do{
if(sum < 10){
continue;
}
sum += i;
i++;
}while(i < 100);
return(sum);
}4. use solidity Implement insertion sort
// Insertion sort
function insertionSort(uint[] memory a) public pure returns(uint[] memory) {
// note that uint can not take negative value
for (uint i = 1;i < a.length;i++){
uint temp = a[i];
uint j=i;
while( (j >= 1) && (temp < a[j-1])){
a[j] = a[j-1];
j--;
}
a[j] = temp;
}
return(a);
}边栏推荐
- Methods of server network testing
- 服务器网络测试的方法
- SQL labs SQL injection platform - level 1 less-1 get - error based - Single Quotes - string (get single quote character injection based on errors)
- The first open source MySQL native HTAP database in China will be released soon! Look at the three highlights first, limited to the surrounding areas, waiting for you~
- Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
- 【QT】capture. Obj:-1: error: lnk2019: unresolved external symbols__ imp_ Htons (solution)
- Lua iterator
- 二零二零年终总结
- 杂谈:把肉都烂在锅里就是保障学生权益了?
- Resttemplate connection pool configuration
猜你喜欢

Usage scenarios for automated testing

DASCTF2022.07赋能赛密码wp

Convert objects to key value pairs

软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术

Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection

DEMO SUBMIT 某程序并获取该程序ALV数据

Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页

存储过程与函数

The seta 2020 international academic conference will be held soon. Welcome to attend!

How to obtain the cash flow data of advertising services to help analyze the advertising effect?
随机推荐
Solidity智能合约开发 — 3.3-solidity语法控制结构
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
LeetCode56. 合并区间
瑞芯微RK3399-I2C4挂载EEPROM的修改案例
C language: optimized Hill sort
Convert objects to key value pairs
DEMO SUBMIT 某程序并获取该程序ALV数据
kalibr标定realsenseD435i --多相机标定
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel
Gossip: it's really important to have a rod in your hand and a net on your shoulder. As for how many fish are in the basket?
End of year summary
什么是真正的HTAP?(一)背景篇
C语言:随机生成数+插入排序
An ordinary autumn recruitment experience
On data security
Hu related configuration
C# 事件用法案例 订阅事件+=
JS access cookie example
Use of NPM
C# 中的转译字符'/b'