compiling error in c++

vidhi gupta's Avatar, Join Date: Nov 2010
Newbie Member
for(int i=0; i< 20;i++)

what is the meaning of this statement and what is the error in this syntex.
virxen's Avatar, Join Date: Nov 2009
Pro contributor
» C Programming Language » C Control Flow » C for Loop Statement
for Loop Statement


for(initialization_expression;loop_condition;incre ment_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-fo...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.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.