Results 1 to 6 of 6

Thread: End Function

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Baltimore
    Posts
    61

    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
    Striver2000

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  3. #3

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Baltimore
    Posts
    61

    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.
    Striver2000

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  5. #5
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: End Function

    Like this?
    VB Code:
    1. void function(){
    2.     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];
    3.     statements;
    4. }

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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
  •  



Click Here to Expand Forum to Full Width