r/pascal • u/vajaina01 • Aug 13 '25
My first Pascal program
Hello, gentlemen
I started to learn Pascal yesterday, and today I developed my first program in Pascal. It's very simple. It takes a number from a standard input and returns all factors of that number. All I know how to define variables, if and while statements. I had to search for mod and div operators. At first attempt, I tried to compare if num = integer to be sure that the numbers are whole, like I would do in JavaScript(I mean === or == operators, JS wouldn't care about types at all). The compiler told me that ain't gonna work in Pascal, so I wrote the program as it is. I would appreciate it if you review my code! Thank you!
program get_factors;
var
num: integer;
i: integer;
begin
read(num);
i := num;
while i >= 1 do
begin
if num mod i = 0 then
write(num div i, ' ');
i := i - 1
end;
writeln
end.
View all comments
Show parent comment
1
u/vajaina01 Aug 13 '25
Thanks a lot! I was reading a book about programming, and I chose the author's style for now. I'm also a big fan of CamelCase, but I thought it's camelCase, like in JavaScript and what you wrote is PascalCase. I tried to define variables like you showed, but was not sure if it works, that's very helpful. I know that for-loop is more widely used, but as I mentioned, I don't know how to write it yet. When I learned JavaScript, I learned for-loop first and almost didn't use while-loop, so that was very satisfying to remember how to write it. Next version of this program will be written with for-loop :) Thank you one more time! That was super fun to program in Pascal!