# Break statement in a for loop

Mehdi Ben Larbi
Ranch Hand
Posts: 70
Hello everyone,

I got confused with this question form the Study Guide ( Chapter 4 ) :

Question : What is the result?

A. same old
B. newly new
C. Compilation fails due to multiple errors
D. Compilation fails due only to an error on line 7
E. Compilation fails due only to an error on line 8
F. Compilation fails due only to an error on line 11
G. Compilation fails due only to an error on line 13

I tired to run it and it's correct.
d2 and d1 are both equal to Days.TH but isn't d2 supposed to be equal to Days.F ?
In the for loop we say: if(d.equals(Days.F)) break;
So how is d equal to Days.TH and not Days.F ?

Thanks.

Ranch Hand
Posts: 42
Mehdi,

Go through each day.

If the current day equals F, then break the loop.

If the current day does not equal F, assign it to d2.

Here we go:

Does M equal F? No. So, D2 equals M.
Does T equal F? No. So, D2 equals T.
Does W equal F? No. So, D2 equals W.
Does TH equal F? No. So, D2 equals TH.
Does F equal F? Yes, BREAK!!!

What was the last value assigned to D2 above?

Hope this helps!

Mehdi Ben Larbi
Ranch Hand
Posts: 70
Thanks a lot,i was focused on the loop and i totally forgot about the if,it's clear now.
Shame on me