Variable

Discussion in 'iOS Development' started by andydam123, Jan 30, 2010.

  1. andydam123

    andydam123 Member

    Joined:
    Aug 11, 2008
    Messages:
    447
    Likes Received:
    0
    Basically what I need is how to do something when a variable reaches a certain amount.
  2. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    idk havent use variables in a while. try this.
    Code:
    if (variable == 3){
           //Action here.
    }
  3. andydam123

    andydam123 Member

    Joined:
    Aug 11, 2008
    Messages:
    447
    Likes Received:
    0
    But it only does the if once, and it takes a while for the varialbe to be the value I need it to.
  4. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    what exactly are you doing?
  5. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Depending on your goal, there are several ways we can solve the problem.
  6. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Yeah, you should seriously learn some basics. Some possibilities:

    • for/while loops - for iterating through something over and over [until some point is reached]
    • goto statements - basically while loops; repeat code until a condition has been reached
    • KVO - if you want to observe a "remote" value"
  7. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    You are changing the variable's value, right? Just after you do, add something similar to what the first replier said

    Please Register or Log in to view images



    http://xkcd.com/292/

    Don't be lazy. Goto is considered a bad habit.
  8. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Whoops! Sorry, I didn't know goto was 'frowned upon.' However, I don't really use it as a loop, rather for skipping parts of a function. What's actually so bad about it?

Share This Page