|
-
Feb 7th, 2005, 05:16 PM
#1
Thread Starter
Member
End Function
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
-
Feb 7th, 2005, 06:24 PM
#2
Frenzied Member
Re: End Function
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?
-
Feb 7th, 2005, 06:43 PM
#3
Thread Starter
Member
Re: End Function
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.
-
Feb 7th, 2005, 07:09 PM
#4
Frenzied Member
Re: End Function
Once one of the if statements is true, it will break out of all of them..That is, if it looks like this;
Code:
if (condition)
{
if (another condition)
{
}
else if (condition)
{
if (another condition)
{
}
}
else
{
}
Now, if you have a bunch of simple if statements, instead of the if-else statements, you might run into problems...
If this doesn't help, would you mind posting just the method?
-
Feb 7th, 2005, 10:31 PM
#5
Fanatic Member
Re: End Function
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;
}
-
Feb 8th, 2005, 07:32 PM
#6
Dazed Member
Re: End Function
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;
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|