Solidity While Loop Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In Solidity, a while loop is a type of loop statement that allows you to execute a block of code repeatedly until a certain condition is met. Syntax: while (condition) { statement or block of code to be executed if the condition is True } The condition is an expression that is evaluated before each iteration of the loop. If the condition evaluates to true, the code inside the loop is executed. Once the code inside the loop is executed, the condition is evaluated again, and the loop continues until the condition becomes false. Example: Below is the Solidity program to demonstrate the execution of a while loop and how an array can be initialized using the while loop: Solidity // Solidity program to demonstrate the use // of 'While loop' pragma solidity ^0.5.0; // Creating a contract contract Types { // Declaring a dynamic array uint[] data; // Declaring state variable uint8 j = 0; // Defining a function to // demonstrate While loop' function loop() public returns(uint[] memory) { while(j < 5) { j++; data.push(j); } return data; } } Output: Comment More infoAdvertise with us Next Article Solidity While Loop T taran910 Follow Improve Article Tags : Solidity Solidity Control-Flow Similar Reads Solidity Do While Loop 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(co 2 min read Swift - While Loop Just like other programming languages, the working of the while loop in Swift is also the same. It is used to execute a target statement repeatedly as long as a given condition is true. And when the condition becomes false, the loop will immediately break and the line after the loop will execute. Wh 2 min read Rust - While Loop Loops in Rust come into use when we need to repeatedly execute a block of statements. Loops are also useful when we need to iterate over a collection of items. In Rust, we have various kinds of loops, including loops, while loops, and for loops. The while loop is the most common loop in Rust. The lo 3 min read While loop Syntax While loop is a fundamental control flow structure (or loop statement) in programming, enabling the execution of a block of code repeatedly as long as a specified condition remains true. Unlike the for loop, which is tailored for iterating a fixed number of times, the while loop excels in scenarios 5 min read PL/SQL While Loop Oracle PL/SQL provides various loop structures that help developers execute a block of code multiple times based on certain conditions. The main loop structures include LOOP ... END LOOP, WHILE ... END LOOP, and FOR ... END LOOP. In this article, we will explore the WHILE loop in detail, including i 5 min read Like