To address the simplest answer:
Swap *never* has to be used. If you want to trade values from X and Y, you can *always* use a temp variable as the go between to do so.
temp = X
X = Y
Y = temp
So why *would* you ever want to use SWAP?
1) Readability. Once you’re used to the command, it’s simply reading and deciphering one single, self-documenting function, in your code.
2) Reduced typing. With expressive character names, or types, it’s much quicker and less strain than typing multiple variables names over and over. Without using SWAP, you type those variable names six times. With it, you only type them twice. Reduce repetitive stress as much as possible — your joints will thank you for it later!
3) Less memory usage and program overhead. Adding a temp variable means allocating the memory for that variable. Now, on modern 128GB systems, 4-bytes isn’t anything to care about, but it’s never a good practice to get into making bloatware. Who knows what microprocessor/system you’ll want to code on in the future?
SWAP *never* has to be used, but generally speaking, it *should* generally be your goto method for swapping two values. When you can use it, use it. Honestly, it doesn’t make any sense not to, that I know of.
Can anyone out there think of a time/reason when it’d be best to use a temp variable as a middleman and manually do the process, ratherthan just use SWAP? I’m honestly drawing a blank on why one wouldn’t use it, when they could.