Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Loops Confusion???  RSS feed

 
Ranch Hand
Posts: 10191
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
Posts: 23813
140
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: 10191
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!

Similar Threads