by putting a loop in your code, which depends on the value of a boolean.
the startvalue is 'true', since you want the code to run at least once.
you just adjust the value of this boolean before you rerun the loop.
you could do this like this:
import javax.swing.JOptionPane;
public class Loopke {
public static void main(String args[]){
boolean condition = true;
int number = 1;
while(condition){
/*
* this will run as long as condition = true, so it will run at least once
* since the original value of condition = true
*/
// enter the code that has to repeat
System.out.println("ran the program: " + number + " times");
number += 1;
int result = JOptionPane.showConfirmDialog(null, "Enter more data?", "REPEAT",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
System.out.println("\tResult of the confirmation: " + result);
// just test this a couple of times, so you see what result you get when pressing 'OK' and what result for 'Cancel'
if ( result != 0 )
condition = false;
}
System.out.println("exit");
System.exit(0);
}
}
stultuske
Industrious Poster
4,374 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24