Variable declaration in "for" loop initialization expression?
Variable declaration in "for" loop initialization expression?
- Subject: Variable declaration in "for" loop initialization expression?
- From: Oleg Krupnov <email@hidden>
- Date: Thu, 18 Nov 2010 13:28:33 +0200
Hi,
I know, this is a very basic question, but after learning so many
programming languages, my head seems like a mess.
In C that is in Objective-C, what is the correct/preferable way to
declare the counter variable in a for loop?
Type i;
for (i = 0; i < N; ++ i) { statements }
or
for (Type i = 0; i < N; ++i) { statements }
Regarding for...in... loop, the docs are very clear that both the
following declarations are valid:
Type existingItem;
for ( existingItem in expression ) { statements }
and
for ( Type newVariable in expression ) { statements }
But what about for (;;) ? The compiler does not point to it as an
error if I declare the counter inside the for () brackets, but I want
to make sure!
Thanks
Oleg.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden