jkjk
jkjk

Reputation: 101

Do/While statements in Java

Is there a way I can make a Do/While statement like this?

do {
    JOptionPane.showConfirmDialog(null, "Do you wish to continue?");
} while (answer == yes);

Upvotes: 0

Views: 138

Answers (2)

dryairship
dryairship

Reputation: 6077

You may change it to:

int answer = JOptionPane.YES_OPTION;
do {
    answer = JOptionPane.showConfirmDialog(null, "Do you wish to continue?");
} while (answer == JOptionPane.YES_OPTION);

Upvotes: 0

Denis Radinski
Denis Radinski

Reputation: 100

Instead of answer == yes, you should check if it equals JOptionPane.NO_OPTION or JOptionPane.YES_OPTION in your case.

Also, you should be having int answer = JOptionPane.showConfirmDialog(null,"Do you wish to continue?);

Upvotes: 3

Related Questions