0% found this document useful (0 votes)
80 views3 pages

Rogram Program1a - Lesson5 Uses CRT Label Return (Used Respectively With The

This document contains code for two programs that demonstrate the use of the case statement. The first program uses case statements to display different messages based on the user's selection of options to play a game, load a game, play multiplayer, or exit. It then uses goto statements to return to the main menu. The second program is similar but avoids using goto statements and instead uses a nested case statement within one of the options. It also demonstrates using an else condition to handle invalid selections.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views3 pages

Rogram Program1a - Lesson5 Uses CRT Label Return (Used Respectively With The

This document contains code for two programs that demonstrate the use of the case statement. The first program uses case statements to display different messages based on the user's selection of options to play a game, load a game, play multiplayer, or exit. It then uses goto statements to return to the main menu. The second program is similar but avoids using goto statements and instead uses a nested case statement within one of the options. It also demonstrates using an else condition to handle invalid selections.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

rogram Program1a_Lesson5; Uses Crt; Label Return; {used respectively with the goto statement; beware of it} Var

SEL : Integer; YN : Char; Begin Return: Clrscr; Writeln('[1].PLAY GAME'); WRITELN('[2].LOAD GAME'); WRITELN('[3].MULTIPLAYER'); WRITELN('[4].EXIT GAME'); Writeln('note: Do note press anything except'); Writeln('numbers; otherwise an error occurs!'); Readln(SEL); If SEL = 1 then Begin Writeln('Are you able to create a game'); Writeln('of yourself using pascal??'); Delay(2000); Goto Return; End; If SEL = 2 then Begin Writeln('Ahhh... no saved games'); Delay(2000); Goto Return; End; If SEL = 3 then Begin Writeln('networking or 2 players?'); Delay(2000); Goto Return; End; If SEL = 4 then Begin Writeln('Exit?'); YN := Readkey; If YN = 'y' then Begin Writeln('Nooooooooooooo...'); Delay(1000); Halt; {EXIT PROGRAM} End; If YN = 'n' then Goto Return; End; End. Now, the next program is almost the same. is written using the case statement and the output

Program Program1b_Lesson5; Uses Crt; Label Return; {use of the goto statement is not recommended..avoid it} Var SEL : Integer; YN : Char; Begin Return:Clrscr; Writeln('[1].PLAY GAME'); WRITELN('[2].LOAD GAME'); WRITELN('[3].MULTIPLAYER'); WRITELN('[4].EXIT GAME'); Writeln('note: Do note press anything except'); Writeln('numbers; otherwise an error occurs!'); Readln(SEL); Case SEL of 1 : Begin Writeln('Are you able to create'); Writeln('a game of yourself using pascal??'); Delay(2000); Goto Return; End; 2 : Begin Writeln('Ahhh... no saved games'); Delay(2000); Goto Return; End; 3 : Begin Writeln('networking or 2 players?'); Delay(2000); Goto Return; End; 4 : Begin Writeln('Exit?'); YN := Readkey; Case YN of {a sort of a nested case statement} 'y' : Begin Writeln('Nooooooooooooo...'); Delay(1000); Halt; End; 'n' : Goto Return; End;{End Case2} End;{Close Conditional Expression 4} End; {End Case1} End.

This source code had a syntax error and is now corrected (Vaar changed to Var)

The Case-Else Statement Again this is similar to the if..then..else statement. Study the program below to learn how to use the 'else' term following the 'case statement': Program Program2_Lesson5; Uses Crt; Label Return; { avoid it } Var YN : Char; Begin Return:ClrScr; Writeln('Exiting?'); YN := Readkey; Case YN of 'y' : Halt; 'n' : Begin Writeln('What are you going to do here, anyway?'); Delay(2000); Halt; End; Else Begin Writeln('Either press ''y'' for yes'); Writeln('or ''n'' for no.. please try again..'); Delay(3500); ClrScr; Goto Return; End; End; {CASE} End. {PROGRAM}

You might also like