Solidity REPL
Syntax & control flow

Tuple assignment swap

Swap two existing variables in one destructuring assignment.

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 tuple assignment swap so its input, result, and state changes stay easy to compare.

Solidity to run

uint256 left = 1
uint256 right = 2
(left, right) = (right, left)

left
right

Official Solidity reference

Compare this focused investigation with the complete language definition in the Solidity documentation.

Destructuring assignments

What to expect

The tuple assignment exchanges both values atomically, so left becomes 2 and right becomes 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