Giter Site home page Giter Site logo

4if-else-objectivec's Introduction

4if-else-ObjectiveC

if else

Boolean Variables

else if

Conditional (ternary) operator

int minutesPerPound;
if (isBoneless)
  minutesPound = 15;
else 
  minutesPerPound = 20
  int minutesPerPound = isBoneless ? 15 : 20;
//
//  main.c
//  ConditionalOperatorTernary
//
//  Created by Carlos Santiago Cruz on 4/21/19.
//  Copyright © 2019 Carlos Santiago Cruz. All rights reserved.
//

#include <stdio.h>
#include <objc/objc.h>

int main(int argc, const char * argv[]) {
    BOOL isBoneLess = true;
    int minutesPerPound;

    if (isBoneLess) {
        minutesPerPound = 15;
        printf("minutesPerPound = %d\n", minutesPerPound);

    } else {
        minutesPerPound = 20;
        printf("minutesPerPound = %d\n", minutesPerPound);
    }

    isBoneLess = NO;

    int newMinutesPerPound = isBoneLess ? 15 : 20;

    printf("newMinutesPerPound = %d\n", newMinutesPerPound);

    return 0;
}

I suspect over time you will embrace the ternary operator as a concise way to do conditional value assigment.

Evaluating a variable with if statement

//
//  main.m
//  IfElseStatement
//
//  Created by Carlos Santiago Cruz on 5/5/19.
//  Copyright © 2019 Carlos Santiago Cruz. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {

        // What happen when you allocate an object an test
        NSString *string = nil;
        string = @"hola mundo";
        if (string) {
            NSLog(@"%@", string);
        } else {
            NSLog(@"say something else");
        }
    }
    return 0;
}
2019-05-05 21:55:14.816827-0600 IfElseStatement[46191:2991491] hola mundo
Program ended with exit code: 0

4if-else-objectivec's People

Contributors

c4arl0s avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.