- Ethereum Smart Contract Development
- Mayukh Mukhopadhyay
- 302字
- 2021-06-24 19:23:55
Coding a loop
Loops are very helpful when we need to repeat the execution of a piece of code a certain number of times. Rather than copying and pasting the same lines of code, making the code block longer, we use this programming construct to add brevity to our code. Loops can be finite or infinite in nature. For the infinite loop, we generally provide a break statement to come out of it.
The smart contract in Figure 3.16 is using a finite loop to calculate the summation of a finite number of integers:

The output on remix IDE is shown in Figure 3.17. As discussed earlier, keep a watch on the amount of ethers that is getting decreased in the Account tab for each call of the myFirstLoop function:

The best way to check the inner working of a loop in runtime is to go to the Launch debugger tab and manually push the horizontal scroll bar from left to right, as shown in Figure 3.18. Try it! It will be fun:

At this point, I hope you are quite comfortable playing with smart contracts using the remix IDE in your browser. However, what I have shown is just a happy-path scenario. The development community for Ethereum is highly agile and is rolling out newer changes very quickly. By the time you start reading this book, there might be slight or major modifications in the IDE. Once you start coding, you will realize the nuances and even capture many peculiar bugs down the line. The next section is all about what you can do when you are stuck with a problem or a code bug.
- 卓越的課件如何做(數(shù)學(xué)篇)
- 感官的盛宴:數(shù)學(xué)之眼看藝術(shù)(萬物皆數(shù)學(xué))
- Blockchain for Business 2019
- 蟻群智能優(yōu)化方法及其應(yīng)用
- 小數(shù)學(xué)家應(yīng)該知道的數(shù)學(xué)故事
- GMAT批判性推理:邏輯分類精講
- 數(shù)學(xué)也可以這樣學(xué):自然、空間和時間里的數(shù)學(xué)
- 幾何之美
- CAE分析大系:ANSYS疑難問題實(shí)例詳解
- Blockchain By Example
- 神機(jī)妙算:一本關(guān)于算法的閑書
- 實(shí)用高等數(shù)學(xué)
- 線性代數(shù)
- 自然哲學(xué)的數(shù)學(xué)原理(漢譯世界學(xué)術(shù)名著叢書)
- Hands-On Cryptography with Python