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

  • SEARCH
  • Home
  • 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 6586945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:51:18+00:00 2026-05-25T16:51:18+00:00

In the following Objective-C code, when first inner ‘if’ statement is satisfied (true), does

  • 0

In the following Objective-C code, when first inner ‘if’ statement is satisfied (true), does that mean the loop terminates and go to the next statement?

Also, when it returns to the inner ‘for’ statement after executing once, does the value of p is again 2, why?

// Program to generate a table of prime numbers

#import <Foundation/Foundation.h>

int main (int argc, char *argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   int p, d, isPrime;

   for ( p = 2; p <= 50; ++p ) {
       isPrime = 1;

       for ( d = 2; d < p; ++d )
            if (p % d == 0)
                isPrime = 0;

       if ( isPrime != 0 )
           NSLog (@”%i ", p);
 }

 [pool drain];
 return 0;
}

Thanks in advance.

  • 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-25T16:51:19+00:00Added an answer on May 25, 2026 at 4:51 pm

    Your code is equivilant to this:

    // Program to generate a table of prime numbers 
    
    import <Foundation/Foundation.h> 
    
    int main (int argc, char *argv[]) 
    { 
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
    
        int p, d, isPrime; 
    
        for ( p = 2; p <= 50; ++p ) { 
            isPrime = 1; 
    
            for ( d = 2; d < p; ++d ) { 
                if (p % d == 0) { 
                    isPrime = 0;
                }
            }
    
            if ( isPrime != 0 ) { 
                NSLog (@”%i ", p); 
            }
        } 
    
        [pool drain]; 
        return 0; 
    } 
    

    The contents of if and for control statements is the next statement or statement block in braces.

    As daveoncode said, you really should use braces.

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

Sidebar

Related Questions

Short and sweet: Why does the following block of Objective-C code not produce a
I'm using the following piece of Objective-C code to format a NSNumber, and it
Another question of mine about optimizing Objective C programs inspired the following: does anyone
While attempting my first sub-class in Objective-C I have come across the following warning
I'm new to Objective C for iPhone. I tried the following code to get
I am just trying to write my very first code in Objective C. I
first of all please let me say that I am quite new to objective
I'm trying to draw the following image: Using this objective-c code: CGContextSetFillColorWithColor(ctx, [[UIColor redColor]
In the book Learn Objective-C on the Mac' you can find the following code
Say I have the following Objective-C class: @interface Foo { int someNumber; NSString *someString;

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.