Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   compiling error in c++ (http://www.go4expert.com/forums/compiling-error-cpp-t23929/)

vidhi gupta 20Nov2010 01:31

compiling error in c++
for(int i=0; i< 20;i++)

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

virxen 20Nov2010 02:26

Re: compiling error in c++
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 20Nov2010 15:59

Re: compiling error in c++
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.

All times are GMT +5.5. The time now is 22:32.