Skip to content

Commit

Permalink
πŸ“ 4-4
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfps committed May 20, 2024
1 parent c74033c commit 6f7308f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions book/src/4-yul-implementations/4-4-yul-actions/4-4-8-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ contract Yul {
}
```

## `while` Loops

To make the `for` loop act like a `while` loop, this is how we do it.

```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Yul {
function infiniteLoop() public pure returns (bytes32) {
assembly {
let x := 0
for { } lt(x, 10) { } {
x := add(x, 1)
}
mstore(0x80, x)
return(0x80, 0x20)
}
}
}
```

## Infinite Loops

To achieve the behaviour of an infinite loop, an approach to the `for` loop is used.
Expand Down

0 comments on commit 6f7308f

Please sign in to comment.