• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Variable declaration in "for" loop initialization expression?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Variable declaration in "for" loop initialization expression?
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Detecting shared folders
  • Next by Date: Re: Variable declaration in "for" loop initialization expression?
  • Previous by thread: Re: error: synthesized properties 'foo' and 'bar' both claim ivar 'myIvar'
  • Next by thread: Re: Variable declaration in "for" loop initialization expression?
  • Index(es):
    • Date
    • Thread