Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 91

Given:

Which loop incurs a compile time error?

    Correct Answer: A

    In the loop starting at line 11, the variable used in the condition 'loop' is not in scope because it was declared within the block that starts at line 1 and ends at line 10. The correct variable to use in the condition of the 'for' loop should be 'loop2', which is declared in the initialization section of the 'for' loop at line 11.

Discussion
StavokOption: A

A is correct TESTED

Stavok

The reason for this is that the loop variable used in the condition of the for loop is not in scope, as it was declared within the block starting at line 1 and ending at line 10. The correct variable to use in the condition of the for loop would be loop2, which is declared in the initialization section of the for loop.

d7bb0b2Option: A

A is correct!

SampsOption: A

A is correct as the variable 'loop' is out of scope (in the condition). took me some time to pick it up.

DenyaarOption: B

The correct answer is B, its using (variable name loop2) in while, when it is defined as loop

Denyaar

This is the same condition with option A

RoxyFoxyOption: D

If we look carefully, the code starts from 1, where the name of the class should be.... We could think that the first two loops are included in the initializer ... it seems strange that it starts without the name of the class at line 1. In this case, the correct answer could be loop starting line 3... It's so confusing...

[Removed]Option: A

A is correct. Cannot redeclare a local variable

[Removed]

Also my bad. 'loop' is out of scope here