PDA

View Full Version : Checking to see if condition is met.




Mettra
Jul 22, 2009, 07:04 PM
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.



-aggie-
Jul 22, 2009, 07:16 PM
variable == "whatever string"

Mettra
Jul 22, 2009, 07:21 PM
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. ;)

dejo
Jul 22, 2009, 07:28 PM
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. ;)
Why run the check in the background? Why not just check it when the button is pressed?

variable == "whatever string"
Besides, that's not how you check a string for equality. You probably wanna use NSString's isEqualToString: instance method.

Kingbombs
Jul 24, 2009, 07:18 PM
do you want something like this
- (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:

for (int i=0; i< 5; i++)
{
// do what ever you need to do 5 times
}

firewood
Jul 25, 2009, 01:43 AM
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.

dejo
Jul 26, 2009, 01:41 PM
do you want something like this
- (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:

for (int i=0; i< 5; i++)
{
// do what ever you need to do 5 times
}
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.