Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2003
    Posts
    138

    Unanswered: What is error in this statement?

    What is error in this statement?
    For (x = 100, x>= 1, x++ )
    System.out.println (x);

  2. #2
    Join Date
    Jan 2004
    Location
    Sochaux (France)
    Posts
    55

    Re: What is error in this statement?

    Originally posted by valexena
    What is error in this statement?
    For (x = 100, x>= 1, x++ )
    System.out.println (x);
    for(x=1, x>=100, x++)

    or

    for(x=100, x>=100, x--)

    Otherwise, you will have infinited loop

  3. #3
    Join Date
    Mar 2004
    Posts
    3
    If you are getting compile errors, it is because you are
    using commas instead of semicolons in between the java
    expressions that specify the parameters for the loop, e.g.:
    use: for (x=0; x<10; x++) , not: (x=0, x<10, x++).

  4. #4
    Join Date
    Jan 2004
    Location
    Sochaux (France)
    Posts
    55
    Originally posted by GaryNichols
    If you are getting compile errors, it is because you are
    using commas instead of semicolons in between the java
    expressions that specify the parameters for the loop, e.g.:
    use: for (x=0; x<10; x++) , not: (x=0, x<10, x++).
    right
    Sorry for my stupid answer

  5. #5
    Join Date
    Jan 2004
    Location
    Melbourne
    Posts
    14

    What is error in this statement?

    Every statement should be ended by semi colon in java.

  6. #6
    Join Date
    Feb 2004
    Posts
    18
    Originally posted by venderic
    right
    Sorry for my stupid answer

    Hi,
    I guess even if the statement were syntatically correct then also it is logically incorrect as you will never enter the loop since the condition will fail. It will result in an infinite loop as said by Venderic... Correct me if I am wrong

  7. #7
    Join Date
    Jan 2004
    Location
    Sochaux (France)
    Posts
    55
    Originally posted by muffi
    Hi,
    I guess even if the statement were syntatically correct then also it is logically incorrect as you will never enter the loop since the condition will fail. It will result in an infinite loop as said by Venderic... Correct me if I am wrong
    It seems to be right.
    Ir was my first feeling.
    But semi colons must replace coma....

  8. #8
    Join Date
    Feb 2004
    Posts
    18
    Originally posted by venderic
    It seems to be right.
    Ir was my first feeling.
    But semi colons must replace coma....
    Yes seemi colon must replace comma.. I am sorry there was a typo in my message... i meant to say that it will not result in an infinite loop rather it wont enter the loop

Posting Permissions

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