Results 1 to 3 of 3
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Double semicolon, why no error?

    This is rather trivial but I'm still interested to know what is going on.

    I was working on a piece of code and accidentally closed off a statement with ;; instead of just ;

    Surprisingly (at least to my novice self) the program compiled just fine and did what it was supposed to do.

    Would one of our good seniors explain to this lowly student why this is so :D

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    Because the empty statement is legal in Java.

    db

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by africanhacker View Post
    This is rather trivial but I'm still interested to know what is going on.

    I was working on a piece of code and accidentally closed off a statement with ;; instead of just ;

    Surprisingly (at least to my novice self) the program compiled just fine and did what it was supposed to do.

    Would one of our good seniors explain to this lowly student why this is so :D
    A Darryl already metioned a single semi colon is the empty statement; your compiler would've protested in situations like this:

    Java Code:
    if (<condition>)
       statement;; // <-- two semicolons
    else // 'else without if' error
       statement;
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 10:40 AM
  2. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  3. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM
  4. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  5. printf error with int and double
    By o0n1 in forum New To Java
    Replies: 1
    Last Post: 09-18-2008, 08:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •