Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Objective C basics

Can someone explain this code to me and what it accomplishes. I don't get it.

    char h = 'h';
    char i = 'i';
    char j = 'j';

    char letter = 'i';
    if (letter == h) printf("letter %c is %c\n", letter, h);
    else if (letter == i) printf("letter %c is %c\n", letter, i);
    else if (letter == j) printf("letter %c is %c\n", letter, j);
    else printf("letter %c is %c\n", letter, j);

3 Answers

It checks if the variable "letter" is equal to h,i or j. In your case, "letter" is equal to "i" which means that it will print the message from the first "else if".

Let me know if I'm wrong.

I think you are right but I'm a long long way from designing an iOS app here. I guess I just have to be more patient. Baby steps....

Thanks for taking the time to answer my question. I would answer some questions but I don't know anything so I'm not much help to anyone yet.