• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Loops Confusion???  RSS feed

 
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Consider the following code,



What's that fuzzy for loop??? it looks like we are saying for(true;true;true) and is this a legal for loop definition.

Thanks in advance.



[HENRY: Formatted Code]
[ November 09, 2006: Message edited by: Henry Wong ]
 
author
Sheriff
Posts: 23607
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jothi Shankar Kumar Sankararaj:
Hi Ranchers,

Consider the following code,

What's that fuzzy for loop??? it looks like we are saying for(true;true;true) and is this a legal for loop definition.

Thanks in advance.




Of course, this is a valid for loop. It actually doesn't matter what is returned from the first and third expressions -- as long as it is a valid java statement that can be executed. As for the second, it needs to be a boolean value, which it is.

Henry
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put any statment ( method call or expression ) or nothing at the first one and the last one but you have to put boolean literal or boolean statment on the middle,
so
for(true, true ,true) = for (literal, literal, literal)
is syntax error

but
for (foo('A'); foo('B')&&(i<2); foo('C'))
= for (statment; statment; statment; )

is legal

and
for (;; is legal too !!!

and
for (;true is legal

and
for (boolean i = true; i ; i = !i) {
System.out.println ("strange questions");
}

is legal
 
Costa lamona
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put any statment ( method call or expression ) or nothing at the first one and the last one but you have to put boolean literal or boolean statment on the middle,
so
for(true, true ,true) = for (literal, literal, literal)
is syntax error

but
for (foo('A'); foo('B')&&(i<2); foo('C'))
= for (statment; statment; statment; )

is legal

and
for (;; is legal too !!!

and
for (;true is legal

and
for (boolean i = true; i ; i = !i) {
System.out.println ("strange questions");
}

is legal


Now I know why Disable smilies in this post option is exist.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

Thanks for the feedback and I got it now. It was worth a discussion.

Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!

Similar Threads