C++ for loops

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

C++ for loops

 
0
  #1
Dec 3rd, 2007
for the for loop

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

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

thank you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C++ for loops

 
0
  #2
Dec 3rd, 2007
(1) The language specification requires them. (2) they separate initialization, condition, and increment statements.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 22
Reputation: people123 is an unknown quantity at this point 
Solved Threads: 1
people123 people123 is offline Offline
Newbie Poster

Re: C++ for loops

 
0
  #3
Dec 3rd, 2007
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.
Last edited by people123; Dec 3rd, 2007 at 1:45 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

Re: C++ for loops

 
0
  #4
Dec 3rd, 2007
thank you!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C++ for loops

 
0
  #5
Dec 3rd, 2007
All of the sections are optional, so we sometimes end up with this: for(;;)
Last edited by Ancient Dragon; Dec 3rd, 2007 at 2:04 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 673 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC