Anyway know the syntax of ending a Function like say if I have an if statement and once that condition is meet I want to exit that function what would that syntax look like in java
Printable View
Anyway know the syntax of ending a Function like say if I have an if statement and once that condition is meet I want to exit that function what would that syntax look like in java
I take it when you say you have an if function and want it to end, your using recursion...am I right?
Or are you talking about a regular loop?
I wouldnt exactly call it recursion a different function calls this other function. Well let me try to make it clearer. I have a function call public void Roll this function performs its operations and at the end it calls the function Roll_Check. Now in the Roll_Check function they are alot of if statements nested if statements and what I want once one of those if statements conditions have been met that in the code that executes that corresponding if statement that somewhere in there I can have the function to stop and exit that function. Cause like some of the if statements change instance variables and once they are changed following if statements will be true when In the program they shouldnt be if the if statement before it had just exited the function or stoped the function.
Once one of the if statements is true, it will break out of all of them..That is, if it looks like this;
Now, if you have a bunch of simple if statements, instead of the if-else statements, you might run into problems...Code:if (condition)
{
if (another condition)
{
}
else if (condition)
{
if (another condition)
{
}
}
else
{
}
If this doesn't help, would you mind posting just the method?
Like this?
VB Code:
void function(){ if(condition) [color=#FF1111]r[/color][color=#D47A2A]e[/color][color=#AAD655]t[/color][color=#7FFE7F]u[/color][color=#55E7AA]r[/color][color=#2A98D4]n[/color]; statements; }
Yeah all you have to do is use the return keyword if you want to terminate the current function call.
Code:public class Example{
public static void main(String[] agrs){
if(args.length != 2){
System.out.println("Need two args!");
return;
}
}
}