私はあなたが2つのことを選ぶことができるプログラムを書こうとしています。 しかし、私が選択したオプションを実行した後、同じオプションの先頭を返すことができるようにしたい。SwitchまたはIfステートメント
switch (option) {
case 1:
System.out.println("Start of option 1");
//option 1 will do things here
System.out.println("End of option 1");
//I want to return at the beginning of this case at the end of it
break;
case 2:
System.out.println("Start of option 2");
//option 2 will do things here
System.out.println("End of option 2");
//I want to return at the beginning of this case at the end of it
break;
default:
break;
}
選択したケースから抜け出すオプションもあります。 また、代わりにif文を使ってやろうとしていることを実装する方が簡単でしょうか?
スイッチまたはifとloopのどちらかでメソッドを使用するだけです。 – Tom
あなたはループが必要なのですか? –