Making a loop

edited December 2013 in Programming Questions

Is it safe to make a method loop like in the code bellow, or is it better to just use a boolean in draw()?

Loop in method:

        void menu() {
              // do some stuff

             //if you didn't get the results that you wanted:
             If(value != 10) {
                  Menu();
               }
        }

Or control in draw?

void draw()  {
      If(control == true)     {
            // do some stuff

           //if you got the results that you wanted:
                 If(value == 10) {
                      control = false;
                   }
             }
     else {
          \\ rest of code
}
}

Answers

  • I don't think it matters in your case because I don't see any loop, unless you are calling menu() from draw continually. Also just a tip, java is very lenient about spacing but it is extremely case-sensitive. Like when you call Menu() on line 6 or say If(...) in the second example, be very careful. Processing could give you an error.

  • Answer ✓

    there's a recursive call in menu, perhaps he means that?

    I'd avoid recursive calls generally. can't tell by the sample what you're trying to do but, generally a while loop is safer.

Sign In or Register to comment.