This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Break statement in a for loop

 
Mehdi Ben Larbi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Answer : A.same old

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.
 
Chad Michaels
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot,i was focused on the loop and i totally forgot about the if,it's clear now.
Shame on me
 
Chad Michaels
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No prob. Happens to everyone!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic