title: Android programming: How do I get out of a while loop?
body: <p>My program should repeat a method until a button is pressed. 
  I tried this, but is doesn't work:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      tts = new TextToSpeech(this, this);
      Button button1 = (Button)findViewById(R.id.button1);
      Button button2 = (Button)findViewById(R.id.button2);
      button1.setOnClickListener(this);
      button2.setOnClickListener(this);
  }
  
  
  public void onClick (View v){
      switch(v.getId()) {
      case R.id.button1: 
          mainprogram();
          break;
      case R.id.button2: 
          perform = false;
          break;
      }
  }
  
  
  
  public void mainprogram(){
  
      while(perform == true){
          speak();
          }
      }
  </code></pre>
  
  <p>(Of course I programmed the "speak()" method)</p>
  
  <p>Could you tell me where the problem is or if there are any methods to solve it?</p>