Skip to main content

Loops and Switch statments

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2012-07-12

I have a switch statement within a Do while loop, i'm wondering if it's possible for the program to save a value from one of the cases and restart checking the switch statements (this would be the loop i imagine) so that the next output would be a different case according to the value it saved from the previous case.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-02-10

If I get it right you want to do somenthing like this:

public class Model{
private int input = 0;
public int getInput(){ return input}
public void changeInputTo2(){ input = 2;}
public void changeInputTo3(){ input = 3;}
// ... set method

// ...
Model m = new Model();

while(model.getInput() != -1){
case 1: model.changeInputTo2(); break;
case 2: model.changeInputTo3(); break;
// ...
// ....