![]() |
VOOZH | about |
In solidity do while loop is similar to the other programming languages firstly it won't check the condition it executes the program at least once which is written in the do block and later it checks the condition in the while block.
Syntax:
do{
// Block of code to be written for execution
}while(condition)
Example: Below is the Solidity program to implement a do-while loop:
Explanation: The above program performs the operation like it takes the index value and it adds plus 1 to the index and stores it in the array. For example at the 0th index, it will store the value 1 and at the 1st index it will store the value 2, and so on it executes the loop till 5 because in while condition we have given a condition less than the length of the array and we declared the array length as 6 in the above program.
Output: