Page 1 of 1

fun with if and switch

Posted: Thu Aug 21, 2008 3:55 pm
by Betelgeuse
If is a simple function that if the condition is true it runs the first function otherwise it runs the second function.

(if cond a b)

Now you can have nested ifs (ifs inside of ifs) A common thing to see is a if as the b function. An easier way to do that is with switch.

A switch is just a condensed form of nested ifs. If put in the if form it would look like this

Code: Select all

(if cond1
	a1 
	(if cond2
		a2
		(if cond3
			a3
			...
			(if condN
				aN
				default
			)
			...
		)
	)
)
The equivalent switch code would be

Code: Select all

(switch 
	cond1 a1
	cond2 a2
	cond3 a3
	...
	cond4 a4
	default
)