
-----------------------------------
Tallguy
Fri Jun 01, 2007 8:23 am

case construct...the easy way
-----------------------------------
Selective structures: Case Construct 

Case construct is an efficient way to creating menus. It does not however allow the coder to do anything that an if statement can't do; it's just better at handling certain tasks. Try this


var command: int 

loop 

put "Choose from 1 to 4:".. 

get command 

case command of 

label 1: 

put "Hi there" 

label 2: 

put "How are you? " 

label 3: 

put "Really?"

label 4: 

put "Bye Bye" 

label: 

put "That is not an option " 

exit 

end case 

end loop


Notice that the final label functions similarly to an else. 

--------------------------------------------------------------------------------------
to practice try these:

1) Write a traffic light program. The traffic light itself should be a graphic. It will flash a light colour at random.Ask the user what colour the light is and output the correct instructions for the chosen light colour. 

2) Write a program that will convert the user's weight to the equivalent weight on any other planet.The user should be able to choose which planet.

3) Modify 2 such that a picture of the planet is displayed.

-----------------------------------
Cervantes
Fri Jun 01, 2007 7:11 pm

RE:case construct...the easy way
-----------------------------------
Again, I fixed up the post. Same comments as in the other one apply.

-----------------------------------
Tallguy
Sat Jun 02, 2007 3:35 pm

RE:case construct...the easy way
-----------------------------------
thanks cervantes
