{
address creator; // reserve one "address" -type spot
uint8 [10] integers; // reserves a chunk của lưu trữ cho 8-bit 10 không xác định Integers trong một mảng
BasicIterator function ()
{
creator = msg.sender;
uint8 x = 0;
// Section 1: Assigning values
while (x
x ++;
}}
function getSum () constant returns (uint) {
uint8 sum = 0;
uint8 x = 0;
// Section 2: Adding the integers in an array.
while (x
x ++;
}
return sum;
}
// Section 3: Killing the contract
function kill ()
{
if (msg.sender == creator)
{
suicide (creator);
}
}
}
Now let's analyze!
In the first step, fill in an array called " integers " which contains 10 8-bit unsigned integers. This will be done through a while loop. Let's see what's happening inside the while loop.
while (xintegers [x] = x;
x ++;
}
Remember, we have assigned the value ' 0 ' to the integer x. The while loop goes from 0 to integers.length . Integers.length is a function that returns the maximum capacity of the array. So if you decide that an array will have 10 integers, the arrayname.length will return a value of 10. In the above loop, the value of x goes from 0-9 (<10) and also assigns the value of itself. it gives integer arrays. So at the end of the loop, integers will have the following values:
0,1,2,3,4,5,6,7,8,9.
Inside the getSum () function, the content of the array itself will be added. That will be done by repeating the same while loop above and using the "sum" variable to add content to the array.
This function ends the contract and sends the remaining amount in the contract to the contract creator.
When asked about the inspiration and motivation behind creating Solidity, Dr. Gavin Woods said:
'It [Solidity] is a sophisticated tool to develop contracts that can ultimately provide both developers and users with information about what the code has done. To help with this, I created NatSpec, a contract-friendly document format, and made it the best option in Solidity. I have also proposed a set of official validation languages (not yet implemented) to maximize the types of tools that ensure accuracy can be implemented.
I introduce things as a best option for Solidity languages to provide an abstract concept for LOGs, similar in form to function calls. The inspiration for that comes from the 'signal' of the Qt meta-object system.
A later feature that Christian R. and I found together was the function of modifying functions; Allow properties to be set as part of the function signature to make some modifications to the content of that function. This language is very suitable for contract-oriented programming ".
This article covered 5 languages used for blockchain programming. In fact, there are many other languages that you can use with the blockchain. If you are a programmer, the development potential is really endless. As the world is increasingly decentralized and blockchain is becoming a more mainstream component, the future for blockchain programming is definitely limitless.
See more: