compiling error in c++

Discussion in 'C++' started by vidhi gupta, Nov 19, 2010.

  1. vidhi gupta

    vidhi gupta New Member

    Joined:
    Nov 19, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    for(int i=0; i< 20;i++)

    what is the meaning of this statement and what is the error in this syntex.
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    » C Programming Language » C Control Flow » C for Loop Statement
    for Loop Statement


    for(initialization_expression;loop_condition;increment_expression){
    // statements
    }


    There are three parts which is separated by semi-colons in control block of the for loop.

    • initialization_expression is executed before execution of the loop starts. This is typically used to initialize a counter for the number of loop iterations. You can initialize a counter for the loop in this part.
    • The execution of the loop continues until the loop_condition is false. This expression is checked at the beginning of each loop iteration.
    • The increment_expression, is usually used to increment the loop counter. This is executed at the end of each loop iteration.

    borrowed from here http://cprogramminglanguage.net/c-for-loop-statement.aspx


    and finally

    The bitwise AND operator (&) compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Taken exactly as stated there is no meaning because of the obvious syntax error: there should only be two semicolons within the brackets. i & lt is valid C; it performs a bitwise AND of i and lt, so it looks like you have four clauses within the brackets, which is incorrect.

    However < is HTML code for the less than sign, so probably this should read
    for (int i=0; i<20; i++)

    in which case there is no error (apart from the missing loop body), and the meaning of the statement is to loop i from 0-19 inclusive.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice