Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:26:01+00:00 2026-05-24T20:26:01+00:00

Is there any different between for(;;) and for(:) in terms of performance in Objective-C?

  • 0

Is there any different between for(;;) and for(:) in terms of performance in Objective-C? And what are good practices to use for(;;) or for(:)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:26:02+00:00Added an answer on May 24, 2026 at 8:26 pm

    I’ll assume that in each case you are enumerating a collection of objects, as only the C for(;;) form allows enumeration of primitive types. The for(in) construction uses a protocol called NSFastEnumeration to fill a buffer with objects to use in future iterations, and uses a cursor to track which object it’s got up to. That makes it faster than:

    NSEnumerator *e = [collection objectEnumerator];
    while (id o = [e nextObject]) {
      //...
    }
    

    which requires one message-send per iteration, and it’s faster than:

    for (NSInteger i=0; i < [collection count]; i++) {
      id o = [collection objectAtIndex: i];
      //...
    }
    

    which also requires one message-send per iteration[*]. The for(in) construct only requires a message send every time the buffer runs dry, which might be once every 8 iterations or so.

    Notice that there’s also block-based looping with [collection enumerateObjectsUsingBlock: ^(id obj, int idx, BOOL *stop){/*...*/}]; which has different properties again. Particularly the version of this construction that takes options can be told to execute the blocks concurrently.

    [*]Observant readers will notice that this actually requires two message sends per iteration, as the termination condition will be evaluated every time through; however it’s so easy to reduce that to one message send that we’ll treat it as one for this discussion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any performance different between hosting your asp.net in mono on linux and
I was wondering is there any difference in terms of performance between the two
What's the difference between String.matches and Matcher.matches? Is there any difference in terms of
Is there any different between NSString * str = @123; and NSString * str
In javascript, is there any different between these two: // call MyFunction normal way
is there any different in Connection string between SQL server Authentication and Windows Authentication
Is there any c# library that handles lossless conversion between different image formats?
Is there any sort of performance difference between the arithmetic operators in c++, or
Is there any difference between the terms(or subjects) Computer Architecture and Computer Organization? If
Is there any difference between these tow pieces of code & which approach is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.