kids encyclopedia robot

Pascal facts for kids

Kids Encyclopedia Facts

Pascal is a programming language. It was created in 1970 by a computer scientist named Niklaus Wirth. He designed Pascal to help people learn how to make computer programs in a clear and organized way.

How Pascal Developed

Over time, many different versions of Pascal have been made. Some of these newer versions can do things like object-oriented programming, which is a way of organizing code using "objects." In 1990, the official rules for Pascal were set by an organization called the International Organization for Standardization.

How Pascal Works

Pascal is a "strongly typed" programming language. This means that every piece of information you use in your program, called a variable, must have a specific data type. For example, you might say a variable will hold a whole number, or text, or a number with decimals. You can only put the correct type of information into that variable. This helps programmers avoid mistakes.

Pascal is also an imperative language. This means you write your code as a list of step-by-step instructions for the computer to follow.

In Pascal, there are two main types of code blocks that do specific tasks:

  • A function is a block of code that does something and then gives back a result (a value).
  • A procedure is a block of code that does something but does not give back a result.

So, you use a function when you need a calculation or a value back, and you use a procedure when you just want to perform an action.

Pascal Code Examples

Here's a simple Pascal program that prints the famous "Hello world!" message on your computer screen:

program helloWorld(output);
begin
        writeLn('Hello world!');
        { which is short for: writeLn(output, 'Hello world!); }
end.

This program tells the computer to display the words "Hello world!" and then move to the next line.

This next example shows how to calculate something called a factorial using a method called recursion. Recursion is when a function calls itself to solve a problem.

program factorialDemo(input, output);

function factorial(n: integer): integer;
begin
        if n < 2 then
        begin
                { the result of a function is stored in a variable }
                { that has the same name as the function: }
                factorial := 1;
        end
        else
        begin
                factorial := n * factorial(n - 1);
        end
end;

var
        n: integer;
begin
        write('Enter number: ');
        readLn(n);
        writeLn(factorial(n));
end.

This program asks you to enter a number. Then, it uses the `factorial` function to calculate the factorial of that number and shows you the answer.

Different Types of Pascal

  • Delphi is a modern tool that uses Pascal. It helps people create programs with graphical user interfaces (GUIs), which are programs with buttons, menus, and windows, especially for Microsoft Windows computers. There's also a free, similar program called Lazarus that works on Windows, Mac OS X, and FreeBSD.
  • Turbo Pascal was a very popular version of Pascal in the 1980s and 1990s, known for being fast and easy to use.

See also

Kids robot.svg In Spanish: Pascal para niños

kids search engine
Pascal Facts for Kids. Kiddle Encyclopedia.