DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   C++ for loops (http://www.daniweb.com/forums/thread99344.html)

dsuh06 Dec 3rd, 2007 1:27 am
C++ for loops
 
for the for loop

for ( ; *source!='\0'; source++)

what is the purpose of the semicolon in the for loop ?

thank you!

Ancient Dragon Dec 3rd, 2007 1:42 am
Re: C++ for loops
 
(1) The language specification requires them. (2) they separate initialization, condition, and increment statements.

people123 Dec 3rd, 2007 1:44 am
Re: C++ for loops
 
in a normal loop you would have
for( i = 0; i < n; i++)

but in your code the semicolon simply states that it doesnt matter what the first section( i = 0) is.

[edit] What AD said. lol.

dsuh06 Dec 3rd, 2007 1:57 am
Re: C++ for loops
 
thank you!!

Ancient Dragon Dec 3rd, 2007 2:03 am
Re: C++ for loops
 
All of the sections are optional, so we sometimes end up with this:
for(;;)


All times are GMT -4. The time now is 3:25 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC