![]() |
is there a problem with...
for ( n = 1; n =< 150; n++; )
this line of code? I continuosly get a syntax error with this line and can find no problem with it. Thank you in advance. |
Re: is there a problem with...
Quote:
Code:
for (n = 1; n =< 150; n++) |
Re: is there a problem with...
Quote:
Traditionally, though, you'd say Code:
for (n=0; n < 150; n++) |
Re: is there a problem with...
and do make sure that you've declared 'n' as well :) but the main problems are probably those already pointed out, i.e. it should be <=, and there should only be 2 semicolons.
|
Re: is there a problem with...
Quote:
|
Re: is there a problem with...
just thought I would emphasize on this for the n00bs.
Code:
for (n = 0; n <= 150; n++) |
Re: is there a problem with...
Quote:
Yes, I meant '3' instead of '4' and I guess I also missed the '=<'. Sorry, and thanks for noticing my mistakes. |
Re: is there a problem with...
One of your comments is off. Your for loop in C:
for ( n = 0; n <= 150; n++) will do this: -set n to zero, run code once -go back to the for statement, add 1, is n <= 150? yes, so run code twice -... -(n is now 150) go back to the for statement, add 1, is n <= 150? no, so stop. The loop will run 151 times, NOT 150 times. Think of a simpler for loop: for ( n = 0; n <= 2; n++) n = 0, execute loop. n = 1, execute loop, n = 2, execute loop, n = 3, stop. If you start at zero and go to 2, the loop runs 3 times - the final valid number, plus one. Which is why you typically see for (n = 0; n < 150; n++) instead. The same reasoning applies to the lower for statement. -Brandon Heller Quote:
|
| All times are GMT -5. The time now is 00:30. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi