Copyright © 2022-2026 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.6·
页面加载耗时 0.00 毫秒·物理内存 104.8MB ·虚拟内存 1304.4MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
Solidity 中, while循环的语法如下:
while (表达式) {
// 如果表达式的结果为真,就循环执行以下语句
......
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;contract SolidityTest {
uint storedData;
constructor() {
storedData = 10;
}
function getResult() public pure returns(string memory){
uint a = 10;
uint b = 2;
uint result = a + b;
return integerToString(result);
}
function integerToString(uint _i) internal pure
returns (string memory) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (_i != 0) { // while 循环
bstr[k--] = byte(uint8(48 + _i % 10));
_i /= 10;
}
return string(bstr);
}
}
运行上述程序,输出结果:
0: string: 12
Solidity do…while 循环: 1. 语法Solidity 中, do…while循环的语法如下:do { // 如果表达式的结果为真,就循环执行以下语句 ......} while (表达 ...