• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Just curious !!

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
If a for loop ends with a semicolon it iters itself till the conditions returns false,why was this need ever to do that ? I am really curious to know why is this treated correct ? and in what scenarios does it benefit the programmer ?
I mean, semicolon in the end doesnt seem to be in line with other statements in terms of syntax ?
and with just the use of a small semicolon u r disfiguring your code too much, i think.
But anyways regardless of my thoughts I guess we have to bow down in front of the compiler ??

Thanks
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are for loops where all the work is done in the header, which can itself contain many statements.


I guess we have to bow down in front of the compiler ??


Actually, a great deal of thought went into existing Java syntax, but the designers are always open to suggestions. As far as I know, there are no compilers on the Java design team. You don't have to bow down to them, just promise to avoid using Internet Explorer.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps it would have been better to have insisted that an empty block "{}", rather than a empty statement (indicated by ";" by itself), was always used to indicate an empty for ( or while ) loop. I'm sure it would have killed a lot of bugs.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry:
Good idea, but adding the rule now would not be backward compatible.
At least "for( .. );" could generate a warning, but javac doesn't do many warnings.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Just because the compiler compiles the code, it doesn't mean the code should be coded that way. After all, line breaks, in most cases, are optional.

*** TANGENT ALERT! TANGENT ALERT! ***
While we are in the neighborhood, I believe the same about if statements. The only time I code a one line if statement is when at the top of a block I have an if statement followed by a break or a continue:


Curiously, the idiom for an infinite loop used to be:


(Edited to disable smilies. For my infinite for loop, the for(;;) displayed as a winking smiley.)
[ December 05, 2004: Message edited by: J Borderi ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic