Pascal_Programming_Syntax_and_Exercises
Pascal_Programming_Syntax_and_Exercises
1. Program Structure
program HelloWorld;
begin
writeln('Hello, world!');
end.
2. Comments
{ This is a comment }
3. Variables
var
age: Integer;
name: String;
price: Real;
isAlive: Boolean;
4. Constants
const
PI = 3.14;
MAX = 100;
5. Input/Output
read(variable);
readln(variable);
write('Text');
writeln('Text');
6. Arithmetic Operators
+ - * / div mod
7. Control Structures
If...Then...Else
writeln('Adult')
else
writeln('Minor');
Case...Of
case grade of
'A': writeln('Excellent');
'B': writeln('Good');
else
writeln('Unknown');
end;
While Loop
while x < 10 do
begin
writeln(x);
x := x + 1;
end;
Repeat...Until Loop
repeat
writeln(x);
x := x + 1;
until x = 10;
For Loop
for i := 1 to 5 do
writeln(i);
Procedure
procedure SayHello;
begin
writeln('Hello!');
end;
Function
begin
Square := x * x;
end;
20 Pascal Exercises with Detailed Explanations and Solutions