Checking to see if condition is met.

Discussion in 'iOS Programming' started by Mettra, Jul 22, 2009.

  1. Mettra macrumors newbie

    Joined:
    Mar 24, 2009
    #1
    I am currently making an application for fun, and I was wondering how to make a check to see if a variable (or variables) have reached a certain value.

    I believe I need to do something with the (void) tag, however I am not sure what...

    Any help is appreciated.
     
  2. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
  3. Mettra thread starter macrumors newbie

    Joined:
    Mar 24, 2009
    #3
    no, not for an if tag. I need some statement running in the background to be constantly checking if a variable equals a number.

    Example: The user presses a button, and variable foo increases by 1. Once foo equals 5 a message displays saying "YAY!" or something. ;)
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Why run the check in the background? Why not just check it when the button is pressed?

    Besides, that's not how you check a string for equality. You probably wanna use NSString's isEqualToString: instance method.
     
  5. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #5
    do you want something like this
    Code:
    - (IBAction)buttonPressed:(id)sender
    {
    int foo = 0;
    while (foo < 5)
    foo++;
    this will increment foo from 0 to 5, and inside the while loop you can do more computation if thats required.

    or:
    Code:
    for (int i=0; i< 5; i++)
    {
    // do what ever you need to do 5 times
    }
     
  6. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    If you want to make it fancy, use a setter for all the variable assignments, and then use notification handlers for all the objects that need to watch the variable.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    I believe the OP wants something whereby each time the button is pressed, the variable is incremented. In that case, the variable will have to be instantiated and initialized outside of the button-press code.
     

Share This Page