caitlin.gif (49145 bytes)


Home ] Search ] Paul Vickers ] Informatics ] Northumbria ]

 

Go to:
Home
Up a level

 

Tutorial: Construct examples

Here we have examples of the basic constructs. To listen click on the 'Play' button next to the source code. You can download an MP3 version by clicking on the link in the Download column. Unfortunately, if you're using Netscape 6.x AND Windows NT then the Media Player plug-in won't work (thanks Microsoft!). In this case you'll have to just download the MP3s and play them on your own media player. Sorry. Also, Netscape 6 doesn't render the scrolling window properly. Sorry again.

Type

Indicative source code

Listen

Download

 

IF yielding
true

a := 10 ;
IF a = 10 THEN
   Writeln ('Hurrah!') ;

Download MP3

IF yielding
false

a := 1 ;
IF a = 10 THEN
   Writeln ('Hurrah!') ;

Download MP3

IF...ELSE
yielding true

a := 10 ;
IF a = 10 THEN
   Writeln ('True')
ELSE
   Writeln ('False') ;

Download MP3

IF...ELSE
yielding false

a := 1 ;
IF a = 10 THEN
   Writeln ('True')
ELSE
   Writeln ('False') ;

Download MP3

CASE with
a match

a := 10 ;
CASE a OF
   2   : Writeln ('Match first') ;
   5   : Writeln ('Match second') ;
  10   : Writeln ('Match third') ;
END ;

Download MP3

CASE with
no match

a := 1 ;
CASE a OF
   2   : Writeln ('Match first') ;
   5   : Writeln ('Match second') ;
  10   : Writeln ('Match third') ;
END ;

Download MP3

CASE...ELSE
with a match

a := 10 ;
CASE a OF
   2   : Writeln ('Match first') ;
   5   : Writeln ('Match second') ;
  10   : Writeln ('Match third') ;
  ELSE : Writeln ('No match found') ;
END ;

Download MP3

CASE...ELSE
with no match

a := 1 ;
CASE a OF
   2   : Writeln ('Match first') ;
   5   : Writeln ('Match second') ;
  10   : Writeln ('Match third') ;
  ELSE : Writeln ('No match found') ;
END ;

Download MP3

WHILE with
2 iterations

a := 1 ;
WHILE (a < 3) DO
   a := a + 1 ;

Download MP3

REPEATwith
3 iterations

a := 1;
REPEAT
   a := a + 1 ;
UNTIL (a > 3) ;

Download MP3

FOR...TO
with 6 iterations

FOR cntr := 1 TO 6 DO
   Writeln (cntr) ;

Download MP3

FOR...DOWNTO
with 6 iterations

FOR cntr := 6 DOWNTO 1 DO
   Writeln (cntr) ;   

Download MP3

 

Email