For loops are key concepts in every software language. Besides being useful and important to structure our code, they will also show themselves in most of the job interviews that we might hopefully have in the future. To succeed in the interviews and to have a better understanding of Solidity, here are some exercises to further our knowledge.
To create this array, we follow these steps:
1. Create an empty uint array
2. Then create a write function so that we can update the state of our array.
3. Then by using for loop, we will push values to the array.
4. The limit for our for loop will be "21" because we want the array to be between 0 to 20.
5. Lastly we will create a view function, to see our array after each click.
6. You can copy-paste this to
Remix, and play with it to practice and learn.
Click on arrows for the next For loop & Array exercise: ⇨ ⇨