I am trying to write a java program that models a while.But keeps crashing. To test it i wrote the following in the textfield : T1[0]=1(i.e Textfield contains 1) This prints "start" onto a label T1[1]=2 increments x T1[2]=3 checks if x<0 and goes back to T1[1] T1[3]=4 Stops the loop Here is part of the code. Any idea why? //x and i are both global variables private class testahandler implements ActionListener { public void actionPerformed(ActionEvent event) { x=-6; for(i=0;i<4 && stop=false;i++) { if(T1.getText().equals("")) { JOptionPane.showMessageDialog( null, "Empty Box" , "ERROR", JOptionPane.ERROR_MESSAGE); return; } else { int OPC=(int)(Integer.parseInt(T1.getText())); OBEY(OPC); } } } } public void OBEY(int op) { switch(op) { case 1:labels.setText("start"); break; case 2:x=x+1; break; case 3: if(x<0) i=1; break; case 4: stop=true; break; default: