Or how can I implement a SWAP(x,y) function in SB?
This doesn't work for me as I thought it might...
a=1 ! b=2
PRINT a,b
swap(a,b)
PRINT a,b
END
DEF swap(x,y)
temp=x
x=y
y=temp
ENDDEF
Many thanks!
Mark
Does SB have a SWAP function?
-
- Posts: 1
- Joined: Sun Jun 10, 2018 5:33 pm
- My devices: iPhone 7+
- Flag:
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Does SB have a SWAP function?
In BASIC language there is no SWAP function.
In any case you will need to use extra assignment to change variables values.
Or more simple way, without a function:
In any case you will need to use extra assignment to change variables values.
Code: Select all
a=1 ! b=2
PRINT a,b
swap(a,b)
a=swap.x ! b=swap.y
PRINT a,b
END
DEF swap(x,y)
temp=x
x=y
y=temp
ENDDEF
Code: Select all
a=1 ! b=2
PRINT a,b
temp=a ! a = b ! b = temp
PRINT a,b
END