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

Is there a trick or syntax to loop again from last value when condition is met?  RSS feed

 
amro talaat
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't understand.. what is the use case?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the type of model, you could use a while loop and reset x (the loop counter) to 0 when you hit that else condition.

Or you could nest loops and have the outer while loop be (while ! done).
 
Liutauras Vilda
Marshal
Posts: 4638
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, amro talaat

Always UseCodeTags (<- click on it) when you post actual code.
I've spent ~3 minutes and gone through your code and added them, as well as fixed code indentation, beside that I added spaces around binary operators, always do that yourself, your code will be more readable, so people who are intended to help you actually could read your code first.

See, it looks the way better now.

Enhanced for loop probably not a good candidate in your case. Consider having simple for or while loop as Jeanne already suggested.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!