• Post Reply Bookmark Topic Watch Topic
  • New Topic

am i better off using a for or while loop?  RSS feed

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amazing...been doing so much,went back to some basics...and i seem to have forgotten

writing a simple program that takes values from the user and then counts them in different iterations.



i know i read that if you dont know your ending value you should use a while loop
but i believe i do know my end value as it is captured in a variable,correct?

also,is it possible to make a for loop without initializing anything,i just want my loop to go from startNumber to endNumber incremented by countNumber

thanks
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:amazing...been doing so much,went back to some basics...and i seem to have forgotten

Yes, it is. And yes, it seems you have.

also,is it possible to make a for loop without initializing anything,i just want my loop to go from startNumber to endNumber incremented by countNumber

In another thread where a moderator cited your past posts, you asked for examples. Well, this is not exactly an example of the kind of random code that sparked the discussion in that thread but it's pretty close. More annoying really is the fact that you can easily answer your own question with a little experimentation and some thoughtful consideration. Have you even tried to do what you're asking about?

Most moderators here are very patient with newbies and we are known to spoon feed folks on occasion. But you've been at this since July and I think it's reasonable for us to expect that you'd be fairly self-sufficient by now and it's honestly a bit annoying when you act like you're a total babe in the woods.
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think for() loops are preferable because all you need to know about the loop conditions are in one place. Start there and change it if there are some mitigating design issues that makes a while() loop more succinct.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!