Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Somebody said that the initialization statement in for() loop is not necessarily to be placed in the for() statement. Can you please clarify this.
Posted

1 solution

You don't have to, no:
C++
for (i = 0; i < 10; i++) {...}
Can be written as:
C++
i = 0;
for (; i < 10; i++) {...}
Or even:
C++
i = 0;
for (;;) 
   {
   ...
   if (++i >= 10) break;
   }
But the first form is normally clearer.
 
Share this answer
 
Comments
Member 10347039 20-Oct-13 3:19am    
Thank you my dear expert
OriginalGriff 20-Oct-13 4:15am    
You're welcome!

BTW: A little cultural advice, if you don't mind!
It is not a good idea to use "dear" online - I know it is perfectly normal in India, but in western cultures if the person you are talking to is female, it can be taken as sexist and patronising - and you never know what gender someone is online! :laugh:
In this case it's fine, there is no problem - but you should consider just leaving the word out in future.
ridoy 20-Oct-13 3:53am    
5ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900