Pascal Program - Print Numbers 1 to 10
Print Numbers 1 to 10
Here is a simple Pascal program to print numbers 1 to 10 to the console window:
Here is a line-by-line description of this program:
program PrintNumbers;
This line declares the beginning of the program and the name of the program is "PrintNumbers".
var
i : integer;
This line declares a variable i of type integer.
begin
This line marks the beginning of the main program block.
for i := 1 to 10 do
This line starts a for loop that assigns the value of 1 to the variable i, and will continue to iterate until i is equal to 10.
write(i, ' ');
This line writes the current value of i to the console, followed by a space. The write function is used to output text or variables to the console.
end.
This line marks the end of the program.
Console Output
The console output of this program would be:
All On the Same Line
It will print numbers from 1 to 10, each number followed by a space, and since there is no writeln, it will all be on the same line.Print Numbers 1 to 10 On a New Line
Replaces "write" with "writeln"
This program uses a for loop to iterate from 1 to 10, the "writeln" function is used to print the current value of the loop variable and move the cursor to a new line after the current number is printed.
By replacing the "write" with "writeln", the program will print each number on a new line.
Console Output
The console output of this program would be:
Each Number on a New Line
It will print numbers from 1 to 10, each number on a new line.
Image by 200 Degrees from Pixabay
Comments
Post a Comment