Thread: Error in compile time

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    51

    Error in compile time

    I have the following:

    Code:
    while
    {
    do something
    }
    #ifndef MQ_SEND
             break;
    #endif
    When I compile, it always shows the error:

    Code:
    break statement canot be outsite while, for or switch
    unexpected end of the file
    Could you please help me?

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,489
    Maybe you could try some valid c code rather than a random stream of characters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    90
    You are using it wrongly, please see:
    do...while loop in C

    Also, a break statement must be inside the loop, yours is clearly after the loop is executed.

  4. #4
    Registered User
    Join Date
    Apr 2017
    Posts
    51
    1. When I put it to while loop, it says invalid end of the file
    2. On the other server it compiles successfully

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    How about providing:


  6. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861
    that is what is called pseudo code. Used to give the other an idea of what is to be written for a loop in this case to work, what you make the do something be is entirely up to the programmer.

    Code:
    while ( condition is true )
    {
       do something;
    }
    // real code
    while ( 1 )
    {
       // do something
       printf("look I'm doing something now\n"
        "someone please make me stop\n");
    }
    //leads to this
    int i = 0;
    while (  1 )
    {
       // do something
       printf("look I'm doing something now\n"
        "someone please make me stop\n");
         i++;
    
       if ( i == 10)
             break;
    
    }
    printf("Thank you\n");
    Last edited by userxbw; 12-15-2017 at 10:30 AM.

  7. #7
    Registered User
    Join Date
    Apr 2017
    Posts
    51
    AIX 1 6 00F636064C00
    compiler CC
    program C
    Code:
    while(!ORA_EOF(&qSelCda))
    {
       qRowCount++;
      d2i_SendXmitRec(&row);

  8. #8
    Registered User
    Join Date
    Apr 2017
    Posts
    51
    AIX 1 6 00F636064C00
    compiler CC
    program C

    Code:
    while(!ORA_EOF(&qSelCda))
    {
    qRowCount++;
      d2i_SendXmitRec(&row);
    if (qRowcount %6 ==0)
       fprintf(qDebug,"\n");
    ORA_CHECK_FETCH(&qSelCda);
    }
    #ifndef MQ_SEND
        break;
    #endif
    When I put last statement into while, it shows the error
    unexpected end of file

  9. #9
    Banned
    Join Date
    Aug 2017
    Posts
    861
    break

    Passes control out of the compound statement.
    The break statement causes control to pass to the statement following the innermost enclosing while, do, for, or switch statement. The syntax is simply
    break;
    C Language Keywords

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,489
    > When I put last statement into while,
    But it isn't in the while is it.
    Look where the closing brace is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile-time error
    By V8cTor in forum C++ Programming
    Replies: 10
    Last Post: 07-11-2015, 06:19 PM
  2. I am getting an error at compile time.
    By Justinweq in forum C Programming
    Replies: 1
    Last Post: 11-19-2013, 06:29 PM
  3. compile time error
    By kapil1089thekin in forum C++ Programming
    Replies: 4
    Last Post: 09-01-2010, 12:29 PM
  4. Compile time error
    By j_spinto in forum C Programming
    Replies: 31
    Last Post: 05-06-2005, 10:41 AM
  5. compile time error...
    By Ruchikar in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2002, 02:51 AM

Tags for this Thread