August 2019
Intermediate to advanced
486 pages
13h 52m
English
You can use loops in two ways as bounded or unbounded loops. If you are performing some operations in contract or just calculating some results, you can use either of the loops.
You can have loops for any function in the Solidity language. However, if the loop is updating some state variables of a contract, it should be bounded; otherwise, your contract could get stuck if the loop iteration is hitting the block's gas limit. If a loop is consuming more gas than the block's gas limit, that transaction will not be added to the blockchain; in turn, the transaction would revert. Hence, there is a transaction failure. Always consider having bounded loops in which you are updating contract state variables for each iteration. ...