(RESTART THE WHILE LOOP)
Ok so I got a loop
How do I do something like that?Code:while(true){
if(bla == 1){
bla bla bla
}else{
return to the start point <<while(true)>>
}
bla bla
bla bla bla
bla
}
Printable View
(RESTART THE WHILE LOOP)
Ok so I got a loop
How do I do something like that?Code:while(true){
if(bla == 1){
bla bla bla
}else{
return to the start point <<while(true)>>
}
bla bla
bla bla bla
bla
}
See Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics), especially the last example on that page
The next to the last example at that link may be what you are looking for.
Ehh ok:
Code:public void run(){
try
{
try
{
lolag://<<<<<<<<< I want it to start from this point>>>>>>>>>>>>>>>
INPUT = new Scanner(SOCK.getInputStream());
OUT = new PrintWriter(SOCK.getOutputStream());
Scanner checkUser = null;
boolean gotusername = false;
boolean gotpassword = false;
boolean allowmenu = false;
boolean gotinmenu = false;
boolean continuep = true;
boolean goteverything = false;
String username = "NotFound";
String userpassword = "NotFound";
while(true)
{
CheckConnection();
if(!INPUT.hasNext())
{ return;}
if(goteverything == false)
{
username = INPUT.next();
userpassword = INPUT.next();
System.out.println("User's username: " + username +"\n" + "User's password: " + userpassword);
goteverything = true;
}
username.replaceAll("\b", "");
userpassword.replaceAll("\b", "");
File userFile=new File(username+".ini");
//File userFile=new File("lionlev.ini");
System.out.println("looking for " + userFile);
boolean exists = userFile.exists();
if(!exists){
OUT.println("wp" + EOF);
OUT.flush();
goteverything = false;
System.out.println("Invalid username.");
break lolag;//<<<<<<<<<<<<I want it to restart from this point>>>>>>
} else {
try
{
checkUser = new Scanner(new File(username+".ini"));
//checkUser = new Scanner(new File("lionlev.ini"));
} catch (Exception e) {}
checkUser.next();
String cpass = checkUser.next();
//System.out.println("Entered pass: " + userpassword);
//System.out.println("REal pass: " + cpass);
if(allowmenu == false){
if(userpassword.equals(cpass)){
System.out.println("Login is alright, sending "+username+ " to the menu..");
OUT.println("ok1" + EOF);
OUT.flush();
allowmenu = true;
} else{
OUT.println("wp" + EOF);
OUT.flush();
System.out.println("WARNING: Wrong password");
goteverything = false;
break lolag;//<<<<<<<<<<<<<<<<<<<<<I want it to restart from this point
}
} else {
System.out.println("allowmenu is true");
goteverything = false;
}
}
if(goteverything == true){
String menu1 = INPUT.next();
while (gotinmenu == false){
if(menu1.indexOf("menu") > -1){
System.out.println("User "+username+ " is in the menu.");
gotinmenu = true;
}
}
}
/*for(int i = 0; i<Connector.ConnectionArray.size(); i++)
{
//Socket TEMP_SOCK = (Socket) Connector.ConnectionArray.get(i);
//PrintWriter TEMP_OUT = new PrintWriter(TEMP_SOCK.getOutputStream());
//TEMP_OUT.println("Someone: " + MESSAGE + EOF);
//TEMP_OUT.flush();
// System.out.println("Sent to: " + TEMP_SOCK.getLocalAddress().getHostName());
}*/
}
}
Simply, it checks if user exists in the file and if the password is right. if not then it restart almost everything
For future reference, that is not an SSCCE. Don't expect unpaid volunteers to wade through your code. In this case you are in luck it is just a syntax error: the label has to identify the loop
Note the location of the label - before the loop, not before the variables that are before the loop.Code:MYLABEL: while(true) {
if ( somecondition ){
break MYLABEL;
}
}