The while loop

There are times when we  need to execute a code segment repeatedly based on a condition. Solidity provides while loops precisely for this purpose. The general form of the while loop is as follows:

Declare and initialize a counterwhile (check the value of counter using an expression or condition) {    Execute the instructions here    Increment the value of counter}

while is a keyword in Solidity and it informs the compiler that it contains a decision control instruction. If this expression evaluates to true then the code instructions that follow in the pair of double-brackets { and } should be executed. The while loop keeps executing until the condition turns false. 

In the following example, mapping is declared along with counter ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.