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 6197133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:45:58+00:00 2026-05-24T03:45:58+00:00

int age == 3; if (age == 2) NSLog(@2); if (age == 4) NSLog(@4);

  • 0
int age == 3;

if (age == 2)
NSLog(@"2");

if (age == 4)
NSLog(@"4");

if (age == 3)
NSLog(@"3");

I was wondering what’s the point of putting else ifinstead of having three if statements.

for (GameObject *character in listOfGameObjects) {
if (character.myGameObjectType == kPowerUpTypeHealth) { 
                characterHealth = 100.0f;
        } 
     }

This is in the Viking.m file. character and self(viking) both have the instance variable, setter and getter method characterHealth. If I want to make Viking’s health equal to a hundred do I have to write self.characterHealth = 100.0f;to make sure the health isn’t added to character? Or is what I already have fine?

Thank you!

  • 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-24T03:46:00+00:00Added an answer on May 24, 2026 at 3:46 am

    The thing is that if you have 3 if statements, all of those conditions will be checked, since age can only have 1 value, you should use

    if (age == 2)  //You need the double equals, to check for equality, if you use one equals it will assign the value and the if statement will always be true.
    
    else if (age == 3)
    
    else if (age == 4)
    

    so after one of those conditions is met, the other conditions will NOT be checked, saving processing time.

    Regarding the self, it will work both ways, however if characterHealth is a @property, using self will assing it using the @synthetize setter, so if you have it declared as retain it will increase the retain count by 1, if you assign it without self it wont increase the retain count. Although since you are assigning it a primitive it doesn’t matter in this case, only objects have a retain count.

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

Sidebar

Related Questions

public class MyClass { public int Age; public int ID; } public void MyMethod()
For example I have a simple class like public class Person{ public int Age
struct person { int age; char name[100]; struct person *next; }; void delfirst(struct person
I have class Person as following : class Person { char* name; int age;
class p { public string Name { get; set; } public int Age {
I have a class: public class MyObject { public string Name; public int Age;
#include <iostream> typedef struct _person { std::string name; unsigned int age; }Person; int main()
I have two domain classes, Alpha and Beta. class Beta{ String betaName int age
How do I sort the below code by name, age and score... all three
Lets say I have this amputated Person class: class Person { public int Age

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.