how to do go to loop in processing...

bpkbpk
edited February 2014 in Programming Questions

for example if my condition doesnot satisfies I have to repeat the execution of certain steps gain can any one please tell me how to do that..

Answers

  • Keyword goto was purposefully not implemented in Java!
    If your intention is restart a loop, just modify its iterator to some starting value!

  • while( !condition ){
      steps;
    }
    
  • or a do-while loop might suit you better than a while loop - it checks the condition after executing once, not before like tfguy's post. subtle difference.

    http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/DoWhileDemo.java

    and both break and continue can use labels if that's what you need. (hard to quite tell from your question)

  • this is a simple program

    int i = 0; 
    
    while (i<5) 
    {
      println ("not there with i being " + i);
      i++;
    }
    println ("---NOW there with i being " + i + "----");
    
  • Answer ✓

    remember that the function draw() in itself loops automatically - so we can also use this loop and just use a variable with if:

    boolean hasTheUserPressedAKey = false; 
    
    void setup () {
      //
    }
    
    void draw () {
      if (hasTheUserPressedAKey == false) {
        println ("not there");
      } // if 
      else {
        println (" ---  there --- ");
      } // else
    }
    
    void keyPressed() {
      // is called automatically when user hits a key
      hasTheUserPressedAKey = true;
    }
    //
    
Sign In or Register to comment.