CodeGym /Courses /Java Syntax /For loop in Pascal

For loop in Pascal

Java Syntax
Level 4, Lesson 12
Available

"Amigo, you won't believe it, but there is a For loop in the Pascal language too. This construct exists in almost every programming language. But in Pascal it's much clearer. Look:"

Pascal
For i := 1 to 10 do
Begin
    Writeln(i);
End;
Java
for (int i = 1; i <= 10; i++)
{
    System.out.println(i);
}
Pascal
For i := 1 to 10 do step 2
Begin
    Writeln(i);
End;
Java
for (int i = 1; i <= 10; i = i + 2)
{
    System.out.println(i);
}
Pascal
For i := 10 downto 0 do step 2
Begin
    Writeln(i);
End;
Java
for (int i = 10; i >= 0; i = i - 2)
{
    System.out.println(i);
}
Comments (25)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Chandan Thapa Level 22, Dubai, United Arab Emirates
4 October 2020
so no need to write (do step 1) in pascal like we used (i++) in java. Interesting!
Maryem Vickers Level 7, HT..., United Kingdom
5 August 2020
Cam on! Of COURSE for loops are in pascal COURSE I'll believe it! I MEAN NEARLY EVERY COMPUTER LANGUAGE HAS IT! XD "Amigo, you won't believe it!" XD LOL XD
David Haines Level 13, La Crosse, United States
8 June 2020
For what it's worth...I come from an RPG background so they both look kinda odd to me. I think they are both easier to understand thanks to learning RPG Free Form. I guess it's all a matter of perspective...
Maryem Vickers Level 7, HT..., United Kingdom
5 August 2020
Yeah.
Ted404 Level 11, Dubai, United Arab Emirates
21 February 2020
I think it would be more reasonable to make a comparison with such languages as Python or C versions. It is good to know Pascal but there is no use of Pascal in 2020 I guess.
Nickolas Johnson Level 8, St. Louis, United States of America
5 March 2020
Python would be the smart choice imo. It's considered either tied with java for the most popular language or it *is* the most popular language.
Erik Kristofer Anderson Level 15, Chicago, United States
14 April 2020
I think choosing Pascal has value for learning, because it has more english words in it than python.
Blaise Level 1, London, United Kingdom
3 May 2020
Agree. For-loop in Java/C/C++/etc is very powerful but looks very cryptic. Python's for-loop is great too, but still not easy on the eye. Just a single blink on the Pascal code, even if you are unfamiliar with it's syntax, makes it very clear what's gonna happen.
Michael Level 10, Dresden, Germany
2 November 2019
Thank you! The more often you mention examples in Pascal, the better I understand why. It is simply a great procedural language and so easy to read.
TheD Level 15, Romania
23 August 2019
If there is a forum discussion about why they chose Pascal to make these examples, please reply to me. I am guessing that they used Pascal because they wanted a programming language that is no longer used and they were afraid that maybe someone will leave the platform to learn that other language elsewhere lol.
Red Level 7, Atlanta, United States
18 January 2020
I think pascal is a little more 'wordy' so its more readable. I feel it just teaches poor syntax in java.
27 May 2019
gimme my dark matter back! joking. Not sure what these pascal lessons are for but it's nice reading through them and have a little "distraction" with something else
Daniel Buyinza Level 13, Kampala, Uganda
20 May 2019
I have question... Why Pascal? Why not C# or C++? The way I see it, comparing with these coding languages would most likely give someone more confidence in case they had to branch out to engage with them as they are highly prominent. However, if the idea is to show us how easy Java is to comprehend in comparison to Pascal. Then I get it.
P.B.Kalyan Krishna Level 22, Guntur, India
29 May 2019
Pascal used to be dominant language for teaching purposes some 30 years back. Now C is the dominant language. Java derives it's syntax partly from C. That is why the author is comparing Java and Pascal now. Another reason may be that Pascal is very strict language as for as it's syntax is concerned. Comparing other languages with Pascal gives us a feedback about the syntax of the present languages.
Jason Macias Level 16, New Jersey, United States
19 June 2019
I also think the idea may be to compare java to a language that is significantly different, but comparable. By thinking through how Pascal might work based on java, it probably helps cement understanding of java, as well as giving an idea of how languages differ for people who haven't tried another language.
Emil Olbinado Level 6, Manila, Philippines
11 April 2019
I don't get Pascal...
Roy Level 22, Bangkok, Thailand
9 April 2019
Am i the only one who immediately skips anything related to Pascal?
Henk Level 19, Pretoria, South-Africa
11 April 2019
Lol! No.
Berkson Level 17, Fortaleza, Brazil
12 May 2019
It was good in its time....
Attila Level 25
25 January 2020
obviously you did not skip immediately, because you felt the urge to comment.