previous page main index next page
 

Semicolons...

You have probably noticed that some lines in your Pascal programs have a semicolon at the end, and some don't. Sometimes, if you forget to put a semicolon at the end of a line, the compiler will report that as an error and refuse to compile your program - it's an easy mistake to make and everyone does it from time to time.

But what are the rules? When is a semicolon required and when does it not matter?

You need to be aware that semicolons are there because they separate one Pascal statement from the next so that the compiler knows where one statement ends and another begins. Here's an example from the program you've just done:

  WRITELN('you are ', age);
  WRITELN('you must be at least ', days, ' days old!')
END.

The semicolon separates the two WRITELN statements but notice that we do not need a semicolon at the end of the second last line - END is a keyword, not a statement, so it doesn't need a semicolon to separate it from the statement on the previous line.

Example 9

This next program is going to ask the user to enter their name, the number of marks they got in a test and the number of marks that the test is out of. We then calculate the percentage and print out the result. For example, Steve Shark might have scored 15 out of 20 and this is 75%

1. Design a Solution

  • write down a complete design for your program
  • show the design to your teacher

2. Code the Program

  • type in the code for your program
  • save it as percent.pas
  • compile and run the program

3. Test the Program

  • as before, draw up a table and choose some suitable data to test the program
  • write a short summary of the results

4. Evaluation

  • write a note giving an evaluation of the program
  • show this to your teacher
     
previous page main index next page
 
© 2001