• Post Reply Bookmark Topic Watch Topic
  • New Topic

Whle Loop statement  RSS feed

 
Timothy Han
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a question about writing while loop statement. Why can't I write a while loop statement like this?



Do I have to write the while loop like this?

If so, what is the reason behind it? Is there a short hand way of writing the while loop statement?


 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

The first structure you posted is called a "for loop", just replace the "while" with "for" and you have it. There are several looping structures, some are common in many languages and some are more rare. Basically, you'll just need to learn the structure of each and when to use them.

Les

BTW: after you change the "while" to "for" change the Tim++1 to Tim++ and it's exactly a common for loop in Java.
 
Timothy Han
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, thanks Les.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A while loop is defined by the language to only have a Boolean expression inside the parens.

"int Tim = 31; Tim < 50; Tim++1" is not a Boolean.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start with the Java™ Tutorials sections.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!