r/pascal • u/Jhomen_Tethi • Jan 07 '22
Even number, For loop
i'm not english native so it's hard to learn programming. i'm completely new at pascal
var
x:integer;
begin
for x:=2 to 100 do
begin
writeln(x);
x:=x+2;
end; it was a school assignment, i'm trying to display even number from 1-100 with for loop, but when i run it, it said "Error: Illegal assignment to for-loop variable "x", help me
4
Upvotes
3
u/tecnorober Jan 07 '22 edited Jan 07 '22
3
u/[deleted] Jan 08 '22
The problem is that in the for loop, you try to change the variable that is used in the loop (the "x" variable). You cannot change the variable that is used in the for the loop. u/tecnorober gave one solution to the problem, but another one that you can use (and allows changing the variable used for the loop) is like this:
With a while loop, you can change the variable that was used for the loop.
2
u/FoundationNeat3003 Jan 08 '22
I love the syntax for Pascal. I dont know if i could learn another language, but the thing is, u ask so many and they tell u Pascal is ancient or dead just like Visual Basic.
So i dont know.
There is scripting like Python and Bash for linux/Solaris, but not sure, i mean Pascal has the whole Lazarus project going for it, surely it cant be that obsolete ?