Results 1 to 10 of 10
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Question Do all over again, how?

    (RESTART THE WHILE LOOP)
    Ok so I got a loop
    Java Code:
    while(true){
    if(bla == 1){
    bla bla bla
    }else{
    return to the start point <<while(true)>>
    }
    bla bla
    bla bla bla
    bla
    }
    How do I do something like that?
    Last edited by Lionlev; 06-06-2012 at 10:33 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Do all over again, how?


  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Do all over again, how?

    Quote Originally Posted by doWhile View Post
    But what if I've got "if" inside of "if" inside of "if" and there is "else" on the last if, and I need to restart the loop in that else statement?
    The examples for that ^^^ didn't work...

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default Re: Do all over again, how?

    The next to the last example at that link may be what you are looking for.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Do all over again, how?

    Quote Originally Posted by Norm View Post
    The next to the last example at that link may be what you are looking for.
    I tried the
    bla:
    break bla;
    It gives me an error "The label bla is missing"

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Do all over again, how?

    Quote Originally Posted by Lionlev View Post
    I tried the
    bla:
    break bla;
    It gives me an error "The label bla is missing"
    That doesn't help us diagnose the problem. Provide an SSCCE that shows what you did.

  7. #7
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Do all over again, how?

    Quote Originally Posted by doWhile View Post
    That doesn't help us diagnose the problem. Provide an SSCCE that shows what you did.
    Ehh ok:

    Java 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());
    					}*/
    				}
    			}

  8. #8
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Do all over again, how?

    Simply, it checks if user exists in the file and if the password is right. if not then it restart almost everything

  9. #9
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Do all over again, how?

    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
    Java Code:
    MYLABEL: while(true) {
            if ( somecondition ){
                break MYLABEL;
            }
        }
    Note the location of the label - before the loop, not before the variables that are before the loop.

  10. #10
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Do all over again, how?

    Quote Originally Posted by doWhile View Post
    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
    Java Code:
    MYLABEL: while(true) {
            if ( somecondition ){
                break MYLABEL;
            }
        }
    Note the location of the label - before the loop, not before the variables that are before the loop.
    Ohhh, thanks! And ok I will do the SSCCE next time..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •