In my project i have a loop that is a simulation of a choice menu and when the user chooses a number i want to go to the next loop but that is a part of a switch statement that is inside the loop. My code is:
while(entrychoice!=8){
String alphabet= "abcdefghijklmnopqrstuvwxyz"; //tyxaio onoma
String onoma = "";
Random random = new Random();
int randomLen = 1+random.nextInt(9);
for(int p = 0; p < randomLen; p++) {
char c = alphabet.charAt(random.nextInt(26));
onoma+=c;
}
//Random rand=new Random();//this.kratisid=kratisid; kai stin main bazo random
//int kratisid=rand.nextInt(500)+100;//Παραγει τυχαιο κωδικο κρατησης μεταξυ 100 και 500
int kratisid = getRandomInt(); //dimiourgia monadikou kai tyxaiou kratisid
Random rand1=new Random();
int afixi=rand1.nextInt(30)+1;//tyxaia mera afixis se ena mina
Random rand2=new Random();
int mdiam=rand2.nextInt(30)+1;//tyxaies meres diamonis se ena domatio
Random rand3=new Random();
int atoma=rand3.nextInt(4)+1;
Domatio d=null;//reference to the domatio pou egine kratisi
reservation r=new reservation(onoma,kratisid,afixi,mdiam,atoma,d);
//r.antistoixisidtodom(d,dom);
Hotel1.addkratisianyroom(r);//prosthiki tyxaias kratisis r se tyxaio domatio
//25% pithanotita gia tyxaia akyrosi kratisis
Random randprob=new Random();
int prob=randprob.nextInt(4)+1;//prob is the probability of cancelling a random kratisi
if (prob==1)//25%
{ //epilogi tyxaias kratisis apo tin lista kratiseon Rlist gia akyrosi
Random randomGeneratorList=new Random();
int index=randomGeneratorList.nextInt(Rlist.size())+0;//+0;
int kratisiFRCID=Hotel1.Rlist.get(index).kratisid;//kratisiFRCid means kratisiForRandomCancel ID
Hotel1.cancelkratisi(kratisiFRCID);//Rlist.get(index).cancel....
}
Scanner scanchoice = new Scanner(System.in);
System.out.println();
System.out.println("Enter \"1\", \"2\",\"3\",\"4\",\"5\",\"6\",\"7\"or\"8\"");
if(scanchoice.hasNextInt()){
entrychoice = scanchoice.nextInt();
}
switch(entrychoice)
{
case 1:
continue;
break;**
}
}
Note that the code continues but is huge and the other options are not the matter.As you see in case1 of the switch statement i want if the user inputs 1 to go to the next loop but the compiler says that break; will never be executed which is something that disrupts my switch statement.Please suggest how to go to next loop with a switch statement and user input as i have done here.Thx in advance.