Results 1 to 5 of 5
  1. #1
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Strange Syntax - at first gkance

    I was working on something and switching between while{} and do while{}. I forgot to
    remove the trailing while and ended up with something like this (the actual loop contents
    and variables were quite different).

    Java Code:
          int a = 0;
          int b = 0;
          while (a < 10) {
             a++;
             b++;
          } while (b < 5);
          System.out.println(a + "  " + b);
    Any way, it took me a few moments to see why this wasn't a compiler glitch. I an using Eclipse Mars.2.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Strange Syntax - at first gkance

    Funny, I thought I'd paste this into my editor (IntelliJ IDEA) but it ruined the fun for me....

    Strange Syntax - at first gkance-while.png
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Strange Syntax - at first gkance

    This is one of those lines that make beginner Java coders scratch their head why this does compile:
    Java Code:
    public class WeirdWhile {
        public static void main(String[] args) {
            http://www.google.com
            System.out.println("foobar");
        }
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Strange Syntax - at first gkance

    Looks like a label and a comment.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Strange Syntax - at first gkance

    Quote Originally Posted by Norm View Post
    Looks like a label and a comment.
    Because that's exactly what it is. It does confuse the new-to-java guys, they are looking at a URL for all they know. They can't seem to separate the two :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Dot Syntax
    By jdodle in forum New To Java
    Replies: 4
    Last Post: 11-09-2013, 08:20 PM
  2. Strange java syntax
    By weps in forum New To Java
    Replies: 3
    Last Post: 09-07-2011, 05:27 PM
  3. Syntax correct?
    By dbashby in forum New To Java
    Replies: 5
    Last Post: 09-22-2009, 06:44 AM
  4. A question about syntax.
    By mr_o in forum New To Java
    Replies: 2
    Last Post: 09-19-2009, 08:30 PM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 03:26 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
  •