While and do-while loops
Compare a precondition loop with a loop that always runs once.
Solidity 0.8.36REPL mode
Why use this example
Use this pattern to isolate Solidity branching, looping, assignment, and function-call syntax before combining it with contract state. The entry isolates while and do-while loops so its input, result, and state changes stay easy to compare.
Solidity to run
uint256 value = 0
while (value < 3) {
value++
}
do {
value--
} while (value > 1)
valueOfficial Solidity reference
Compare this focused investigation with the complete language definition in the Solidity documentation.
Control structuresWhat to expect
The while loop raises the value to 3, then the do-while loop lowers it until the final value is 1.
Continue the investigation
Change a value, add another expression, or open Inspect after the run. Accepted entries remain available to the next entry, and the clean replay keeps the complete result reproducible.
Read about writing Solidity Prototype Solidity behavior