CodeGym /Courses /Java Syntax /Conditions from Planet Pascal

Conditions from Planet Pascal

Java Syntax
Level 4 , Lesson 5
Available

"Hi, Amigo. On our planet, we use Pascal, which is more advanced. This is how it would look in Pascal."

Pascal
If a < b Then
    WriteLn ('a is less than b');
Java
if (a < b)
    System.out.println("a is less than b");
Pascal
If a < b Then
    WriteLn('a is less than b')
Else
    WriteLn('a is greater than b');
Java
if (a < b)
    System.out.println("a is less than b");
else
    System.out.println("a is greater than b");
Pascal
If a < b Then
    Begin
        WriteLn('a is less than b');
        WriteLn('a is less than b');
    End
Else
    Begin
        WriteLn('a is greater than b');
        WriteLn('a is greater than b');
    End;
Java
if (a < b)
{
    System.out.println("a is less than b");
    System.out.println("a is less than b");
}
else
{
    System.out.println("a is greater than b");
    System.out.println("a is greater than b");
}

Pascal
If a < b And a < c Then
    WriteLn('a is the minimum of a, b, c');
Java
if (a < b && a < c)
    System.out.println("a is the minimum of a, b, c");
Pascal
If a < b Or a < c Then
    WriteLn('a is either less than b, or less than c');
Java
if (a < b || a < c)
    System.out.println("a is either less than b, or less than c");
Pascal
If Not (a < b) Then
    WriteLn('b is less than or equal to a')
Else
    WriteLn('b is greater than a');
Java
if ( !(a < b) )
    System.out.println("b is less than or equal to a");
else
    System.out.println("b is greater than a");
Pascal
If a < b Then
    Begin
       If a < c Then
            WriteLn('a is the minimum')
        Else
            WriteLn('c is the minimum');
    End
Else
    Begin
        If b < c Then
            WriteLn('b is the minimum')
        Else
            WriteLn('c is the minimum');
    End;
Java
if (a < b)
{
    if (a < c)
        System.out.println("a is the minimum");
    else
        System.out.println("c is the minimum");
}
else
{
    if (b < c)
        System.out.println("b is the minimum");
    else
        System.out.println("c is the minimum");
}
Pascal
If a <= b And a <= c Then
    WriteLn('a is the minimum')
Else If b <= a And b <= c Then
    WriteLn('b is the minimum')
Else If c <= a And c <= b Then
    WriteLn('c is the minimum');
Java
if (a <= b && a <= c)
    System.out.println("a is the minimum");
else   if (b <= a && b <= c)
    System.out.println("b is the minimum");
else   if (c <= a && c <= b)
    System.out.println("c is the minimum");
4
Task
New Java Syntax, level 4, lesson 5
Locked
Multiplication table
Use any kind of loop to display a 10x10 multiplication table. Separate the numbers with spaces. Example output: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 7
Comments (42)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
4 July 2021
It's funny you are using Pascal code to teach Java, but on the other hand Delphi was very successful in Russia. Anyone remembering torry.ru :D? Good times.
acg.comured Level 4
1 July 2021
ok
Eros nullfeathers Level 4, Salt Lake City, United States
23 April 2021
Its interesting that they mention pascal here. My first program was written in Turbo Pascal in the 90's. It was for a magnet class that the high school provided for computer science. We wrote the snake game back then and used local email among the students. It was great!
ImDevin Level 15, Old Town, United States
30 March 2021
why Pascal here?
Luke Level 5, Brisbane, Australia
12 April 2021
Good question, I also would like to know
John Solomon Legara Level 8, Makati, Philippines
4 May 2021
I'm guessing it's to show us how similar / different the languages are...
Sinisa Level 11, Banja Luka, Bosnia and Herzegovina
16 February 2021
I used Delphi (i.e. Object Pascal) back in the day, it was fairly popular but in a steady decline since the 90s.
Alaskian7134 Level 22, Iasi, Romania
12 November 2020
should we try to learn pascal while learning java?
jbajaj Level 9, Baltimore, United States
20 December 2020
I would recommend Python, it's simpler than Pascal, and much more prevalent.
Chandan Thapa Level 22, Dubai, United Arab Emirates
3 October 2020
point to look carefully - hope you all noticed the differences, between the two.. I almost missed how they have used the semicolon (;) differently in Pascal. Great lesson!
Mihai Bone Level 8, Bucharest, Romania
30 September 2020
I am always wondering what Elon Musk, Bill Gates and Steve Jobs had in common.
Jordi Claes Level 17
5 February 2021
All of them are richer than any human being should be allowed too?
Nathan Guidry Level 6, Lake Charles, United States
13 May 2021
I think he means personality wise..
Andrei Level 41
18 September 2020
But for the last example shouldn't there be curly braces for the Java example?
Kim Level 5, San Mateo, United States
23 September 2020
Not in that case. Java only uses curly braces for else-if conditions when there are multiple statements to be executed. In the last example, each line is a new "if" or "else-if" so curly braces aren't needed. Here's another way to look at it:

if (conditional)
    Statement 1
else if (conditional)
    Statement 2
else 
    Statement 3 
vs.

if (conditional) 
{
    Statement 1; 
    Statement 2; 
}

Dinesh Level 7, Delhi, India
18 January 2021
This is known as if else-if ladder
Agent Smith Level 38
6 August 2020
When you are learning one programming language, you are also learning many others as well, because a lot of syntax might be the same or very similar across many languages. Also, basic concepts are the same and etc. So once you are good with one language, it is much-much easier to start working with another one.