[comp.lang.pascal] Function of semi-colon in Pascal

cslaurie@cybaswan.UUCP (Laurie Moseley ) (06/28/91)

This was posted recently:.................

<  confirm : boolean;
<  key     : char;
<
<begin
<  confirm := false;
<  key     := '0';
<  case key of
<    '1' : Menue1;
<    '2' : Menue2;
<    '3' : Menue3;
<    '0' : if confirm then
<            RequestExit;
<          else
<            FastExit;
<  end;
<end;
<
<This piece of program would compile OK, but I could never manage to
<get a FastExit! 
<Peter Knoerrich,        email: prknoerr@faui43.informatik.uni-erlangen.de
------------------------------------------------------------------------

I expected that this piece of code would not compile. The semi-colon
before the "else" means that a statement separator is coming in the
middle of a statement. In other words, there is a new statement beginning
with the word "else". It is as though you BEGAN a sentence with

 	Otherwise, go to the cinema ...

Anyway, I tried it out of curiosity, and sure enough it did not compile
(and it shouldn't). 

Once you delete that semi-colon, it will compile, but its behaviour is
precisely the opposite of that reported. As the boolean variable <confirm>
is set to <false> and is never changed, the condition for RequestExit is
never satisfied, so it will always FastExit.

==========================================================================

Laurie Moseley

Computer Science, University College, Swansea SA2 8PP, UK

Tel: +44 792 295399

JANET:	cslaurie@uk.ac.swan.pyr

=========================================================================
"Why does the Turing test set such abysmally low standards ?"
===========================================================================

pshuang@athena.mit.edu (Ping-Shun Huang) (07/01/91)

In article <2580@cybaswan.UUCP> cslaurie@cybaswan.UUCP (Laurie Moseley ) writes:

 > I expected that this piece of code would not compile.
   [....]
 > Anyway, I tried it out of curiosity, and sure enough it did not compile
 > (and it shouldn't). 

At least in Turbo Pascal, there is a provision for a CASE-ELSE
statement, so the above code is acceptable on certain compilers.

Peter, to get your code to do what you want: (a) remove the semicolon
after "RequestExit"; (b) put in some way for the user to change the
value of the variable "confirm".

--
Above text where applicable is (c) Copyleft 1991, all rights deserved by:
UNIX:/etc/ping instantiated (Ping Huang) [INTERNET: pshuang@athena.mit.edu]