1. - Top - End - #10
    Titan in the Playground
     
    Silverraptor's Avatar

    Join Date
    Feb 2009
    Location
    A nice, sparkly place.
    Gender
    Male

    Default Re: I'm learning Java accelerated and I need help

    Quote Originally Posted by jayem View Post
    If (as shown and noted) it's declared before the loop it will be existing for the whole loop and until the next } braces (for good and ill).
    If it's declared in the loop then it becomes a bit complex (I think it might still work if you test at the end like that).
    If you took the switch to be a function in it's own right, then you will have problems
    Spoiler: pseudocode
    Show

    Code:
      public main(){
        ...
        boolean repeat=true;
        while(repeat){
            this.switchFn();
        }
      }
      private void switchFn(boolean repeat){
          Switch...
          ...
            repeat=false;
      }
    Would loop for ever (if you fixed it to compile)
    This is similar to how I did it. I put a Boolean value as True outside the do/while loop and if none of the cases in the Switch statement are satisfied, then the true value would hit the while part of the loop and go back to the top of the do loop.


    Edit: Nevermind! I just realized why I was doing this wrong. I was thinking about this from a C++/Machine Assembly way. I was trying to move through the code, into and out of loops. But now I realize, I don't want to move out of the loop. I just have that case call a method, which would then call another method and so on and so forth, while not actually leaving the loop! And then I can have the last method I'm calling have the exit or close out command which would shut down the application then! Is this correct? If so, then my mind would be blow by this revelation!
    Last edited by Silverraptor; 2019-04-25 at 04:30 PM.
    My own webcomic. Idiosyncrasy.
    Paladin Academy: Chapter 2 Part 28

    *Avatar by Me*