Skip to main content

Loops and Switch statments

1 reply [Last post]
TopRock
Offline
Joined: 2012-07-12
Points: 0

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.
kauedb
Offline
Joined: 2009-02-10
Points: 0

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();
m.setInput(1);

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