WWW Pascal Programming Info Lesson5 PHP
WWW Pascal Programming Info Lesson5 PHP
info
A step-by-step Pascal tutorial for beginners.
Home
Lesson 1
The First Few Steps in
Pascal Programming
Lesson 2
Variables & Constants
Lesson 3
Special Functions of the
CRT Unit
Lesson 4
Program Flow Control
Lesson 5
The Case-Of Statement
Lesson 6
Before continuing with this lesson, make sure that you have learnt to use 'if
statement' (lesson 4)
In a nutshell, this lesson will cover:
The Syntax of the CASE-OF Statement
The CASE-OF-ELSE Statement
Lesson 7
Procedures & Functions
Lesson 8
open in browser PRO version
pdfcrowd.com
Lesson 8
File Handling
Lesson 9
Arrays
So
Lesson 10
Lesson 11
Record Data Structure
Advanced
Programming
Concepts
far,
you
have
pdfcrowd.com
Program Program1a_Lesson5;
Uses Crt;
Label Return; {used respectively with the goto
statement; beware of it}
Var SEL : Integer;
YN : Char;
Donate 5 via
PayPal and get an
offline PDF
version of this
tutorial in return.
Support PascalProgramming.info
with your
generous
donation!
Click here to
Donate & Get
PDF
Begin
Return: Clrscr;
Writeln('[1].PLAY GAME');
WRITELN('[2].LOAD GAME');
WRITELN('[3].MULTIPLAYER');
WRITELN('[4].EXIT GAME');
Writeln('note: Do not press anything
except');
Writeln('numbers; otherwise an error
occurs!');
Readln(SEL);
If SEL = 1 Then
Begin
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
PDF
Thank you :)
pdfcrowd.com
If YN = 'y' Then
Begin
Writeln('Good Bye...');
Delay(1000);
Halt; {EXIT PROGRAM}
End;
If YN = 'n' Then
Goto Return;
End;
End.
Now, the folowing program is written using the case-of statement instead
of the if statements and the output
is exactly the same.
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');
open in browser PRO version
pdfcrowd.com
WRITELN('[4].EXIT GAME');
Writeln('note: Do not press anything
except');
Writeln('numbers; otherwise an error
occurs!');
Readln(SEL);
Case SEL of
1 : Begin
Writeln('You
will soon be able to create');
Writeln('games
using Pascal Programming :-)');
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;
open in browser PRO version
pdfcrowd.com
End;
4 : Begin
Writeln('Exit?');
YN := Readkey;
Case YN of {a
sort of a nested case statement}
'y' :
Begin
Writeln('Good Bye...');
Delay(1000);
Halt;
End;
'n' :
Goto Return;
End; {End Case
2}
End; {Close Conditional
Expression 4}
End; {End Case 1}
End.
Back To Top
pdfcrowd.com
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('Press either
''y'' for yes');
Writeln('or ''n'' for
no.. please try again..');
open in browser PRO version
pdfcrowd.com
Delay(3500);
ClrScr;
Goto Return;
End;
End; {CASE}
End. {PROGRAM}
Basically, what the code does above is that if the input is none of 'y' or 'n',
then program flow falls to the 'else' of the case statement - its like an 'if all
else fails'. It works like the last 'else' of the if statement.
Back To Top
12
Recommend
Pascal-Programming.info
Share
pdfcrowd.com
Reply Share
Victor Saliba
Mod
Reply Share
Carsen > Victor Saliba 4 months ago
Reply Share
Dehvaughnte hinds 5 months ago
Reply Share
pdfcrowd.com
Medunoye
Subscribe
Privacy
Back To Top
pdfcrowd.com
pdfcrowd.com