当前位置:网站首页>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);
}边栏推荐
- How to obtain the cash flow data of advertising services to help analyze the advertising effect?
- Harbor can't log in with the correct password
- Applet payment management - new payment docking process
- 帮个忙呗~不关注不登录,不到一分钟的一个问卷
- A quick overview of transformer quantitative papers in emnlp 2020
- 软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
- How to analyze and locate problems in 60 seconds?
- 「翻译」SAP变式物料的采购如何玩转?看看这篇你就明白了
- Gossip: is rotting meat in the pot to protect students' rights and interests?
- Shell awk related exercises
猜你喜欢

How to obtain the cash flow data of advertising services to help analyze the advertising effect?

自动化测试的使用场景

Things come to conform, the future is not welcome, at that time is not miscellaneous, neither love

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

帮个忙呗~不关注不登录,不到一分钟的一个问卷

【pytorch】ResNet18、ResNet20、ResNet34、ResNet50网络结构与实现

The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?

C commissioned use cases

Leetcode54. 螺旋矩阵

Usage scenarios for automated testing
随机推荐
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?
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
[QT] unable to open the containing file pcap.h (C1083) in QT creator
容器内使用sudo报错bash: sudo: command not found解决
Lua迭代器
Shell functions and arrays exercises
The token verification of applet message push configuration failed. Please check and confirm
[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement
Methods of server network testing
API 版本控制【 Eolink 翻译】
SQL labs SQL injection platform - level 1 less-1 get - error based - Single Quotes - string (get single quote character injection based on errors)
C# 事件用法案例 订阅事件+=
HU相关配置
API version control [eolink translation]
Demo submit a program and obtain ALV data of the program
物联网工业级UART串口转WiFi转有线网口转以太网网关WiFi模块选型
Convert objects to key value pairs
大家节日快乐哈
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
Practical new drug R & D project management platform