No of visitors who read this post: 178
Category: Pascal
Type: Question
Author: Luisantos
No votes yet

what is the difference between using ":" and ";"  in TPW program and is it  obligatory to use it?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

#

Hello Luisantos.

Colons (:) in Pascal are used in declaration of variables.  Examples are:

program codesnippet;

var
 x_int, y_int: integer;
 z_real: real;

Notice how the colon separates the variable "x_int" and "y_int" from the data type "integer".  It also separates the variable "z_real" from the data type keyword "real".  Without the colon, the compiler will return a syntax error.

Notice in the same example that there are semi-colons (;) right after each line of code.  The semi-colon indicates the end of a program statement in Pascal.

Obligatory?  Yes, it is.  The colon and semi-colon are part of the syntax of a Pascal program.  Without it, it will be impossible to compile the source code into an object.  Not being able to compile will mean it will not be possible to build the object file into an executable.

#

In Pascal, the colon “:” symbol has many uses. It can be used in the declaration of a variable “var” or constant “const” to specify its identifier type. It can also be used in specifying a “case” statement entry. You can use it to separate the function type from function declaration. Similar to batch file programming, the colon symbol can be used to declare a label.

The semicolon “;” symbol shows the end of a statement. This symbol is mandatory and should appear after each statement. But there are also cases where the semicolon symbol is optional and sometimes forbidden. The locations where you can place this symbol optionally are either before the period at the end of a “UNIT” or “PROGRAM”, or before the “END” statement. On the other hand, you cannot use the semicolon symbol before the “BEGIN” statement or before an “ELSE” clause in a nested “IF” statement.

Regards
Sharath Reddy