This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's wrong with the for-each

 
Bin Qian
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone:
here is the code



the program calculates the average of sumOfNumber(a variable in the program) integers, and the sumOfNumber is enterd by users also the number;
when i use comment(1) it's ok,but it doesn't work when i use commnet(2), why???
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "doesn't work" do you mean doesn't compile? If so, check the version of Java you are using; the for : each syntax is only available from v5.0 up.

If by "doesn't work" you mean something else, can you lease explain what that is (by describing the behaviour and/or posting any stack trace you have)?
 
Anton Uwe
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The foreach-loop (as in //(2)) is equivalent to

There is no "reassignment" like "number[i]=nb".
 
Bin Qian
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok !thank you everyone espatically Anton Uwe!
i see now!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic