Java Programming - Flow Control - Discussion

Discussion Forum : Flow Control - Finding the output (Q.No. 20)
20.
What will be the output of the program?
int i = 0, j = 5; 
tp: for (;;) 
    {
        i++;  
        for (;;) 
        {
            if(i > --j) 
            {
                break tp; 
            } 
        } 
        System.out.println("i =" + i + ", j = " + j);
i = 1, j = 0
i = 1, j = 4
i = 3, j = 4
Compilation fails.
Answer: Option
Explanation:

If you examine the code carefully you will notice a missing curly bracket at the end of the code, this would cause the code to fail.

Discussion:
17 comments Page 2 of 2.

Aravindh said:   1 decade ago
What is tp: kindly explain me ?

Alex said:   1 decade ago
If compilation fails for the lack of the ending curly brace, compilation would fail for the lack of a main function. These questions imply the code snippets are just that - snippets - and so it would be perfectly reasonable to assume there is a curly brace later on in the code but not included in the snippet. That doesn't change the fact that the print statement is unreachable though.

Ghogale said:   1 decade ago
No, I run that program it give error unreachable statement at

System.out.println("i =" + i + ", j = " + j);

Mehul said:   1 decade ago
If curly brackets would have been there in corrrect pos then answer would be i= 1 and j=0.

Jhon said:   1 decade ago
There is no main method which is to be noticed.

Siavash said:   1 decade ago
There is no break; in the second eternity loop, which would make the System. Out. Println an unreachable statement.

Firat said:   1 decade ago
Well, it would be better to ask the output without any missing curly brackets.

Then answer would be i = 0, j = 0, I guess.


Post your comments here:

Your comments will be displayed after verification.