Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

increment problem in for loop  RSS feed

 
H. J. Yoshi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it invalid to increment or decrement the loop variable in java by a value greater than 1?I get an error if write a loop as:

for (int i=0;i<100;i+10)

Pls help.
Thanks
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can increment a value greater then one.

The problem is i+10, where does the new value get stored with no assignment operator?
 
H. J. Yoshi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can increment by 10, but you are not incrementing anything in your example. Infact it wont compile. You will need to do something like:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!