PDA

View Full Version : Getting Out of a Button Press Routine


stocktonlad
01-02-2008, 10:26 AM
I've got an on press routine with serveral "IF" statements.

Is there a way of exiting a routine once a condition has been met.

I do a lot of VB and I would use EXIT SUB, is there an AS equivalent.

Many Thanks

John

creynders
01-02-2008, 11:25 AM
break

stocktonlad
01-02-2008, 11:49 AM
Many Thanks

John

Nomad2000
01-03-2008, 04:27 AM
A break; will only break you out of a loop or a switch, not an if.

If you are in a loop with ifs inside it then you may be able to use break; to get out of the loop, and if that is the end of your method then you would be fine.

To exit immediately from anywhere in a function though, just use return; or return someValue;.

panel
01-03-2008, 08:12 AM
what about else if

if(a == 5)
{

}
else if (a == 6)
{

}

hangalot
01-03-2008, 09:24 AM
i think a switch might be more appropriate

stocktonlad
01-03-2008, 09:51 AM
Thanks. You're right, "break" didn't work right.

I have now used "switch" which is doing the job great.

Cheers

John

xwielder
01-03-2008, 11:09 AM
Invoking a Switch statement to exit an IF condition?? Use RETURN.


if (myArray[0] == 1)
{
trace("Hello World");
return;
}


Return statement
The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point, regardless of whether it's in the middle of a loop, etc.

hangalot
01-03-2008, 11:10 AM
i think you missed the point.

xwielder
01-03-2008, 11:26 AM
i think you missed the point.

How so?

I've got an on press routine with serveral "IF" statements. Is there a way of exiting a routine once a condition has been met.

I don't see a hidden 'point'.

hangalot
01-03-2008, 11:58 AM
switch(myVar)
{
case 1:
//asdasd
break;
case 2:
//asdasd
break;

}

cleaner syntax and easier to change in the long run.