Conditionals II

Multilevel conditional words help your program make more than one decision. Here's an example:

		: say-my-name
			dup 2 =   	->  "Two!"    	  |
			
		        dup 3 =   	->  "Three!"  	  |
		
			    4 =   	->  "Four!"  	  |
		
		         otherwise  	    "Whatever"    |.
			. cr 
		;
	
Take your time to understand
SAY-MY-NAME
. Some pointers:

Quiz

Question 1

Run

		0 say-my-name
		1 say-my-name
		2 say-my-name
		3 say-my-name
		4 say-my-name
		10000 2 + say-my-name
		
Do you understand how
SAY-MY-NAME
works?



Question 2

Extend the program 
SAY-MY-NAME
so that it says the name of the number 43. Remember to check that your program works. What do all the
DUP
s do?



Question 3

What would happen if we left out the 
OTHERWISE
part from
SAY-MY-NAME
? What changes would you have to make to it so that it works perfectly? Test out your answer.



Next: Text and Strings