Generic swap: Difference between revisions

Content added Content deleted
(Generic swap in BASIC256)
(Generic swap in QBasic)
Line 2,645: Line 2,645:
return b, a</lang>
return b, a</lang>
Note that tuples are immutable in Python. This function doesn't mutate anything, but simply returns a new pair with the order of the elements switched.
Note that tuples are immutable in Python. This function doesn't mutate anything, but simply returns a new pair with the order of the elements switched.

=={{header|QBasic}}==
QBasic already has a generic swap procedure built in, but a new subroutine can be defined:
<lang qbasic>SUB nswap (a, b)
temp = a: a = b: b = temp
END SUB

a = 1
b = 2

PRINT a, b
CALL nswap(a, b)
PRINT a, b</lang>


=={{header|Quackery}}==
=={{header|Quackery}}==