fun with if and switch

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

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
)
Crying is not a proper retort!
Post Reply