why doesn't my loop continue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nobody4406
    New Member
    • May 2015
    • 3

    why doesn't my loop continue

    I'm trying to write a program that asks the user to enter a single letter untill they enter a (.) They hit enter after each letter, but the loop wont continue. It asks them to enter a letter, then it sks for another letter (because it's not a peroid) but then it just stops. The loop doesnt continue. Even if they enter a peroid the second time, it wont accept it.

    Code:
     public class J12Q5
    // counting letters
    {
        public static void main(String[]args) throws IOException
            {
                InputStreamReader inStream = new InputStreamReader(System.in);
    		BufferedReader stdin = new BufferedReader(inStream);
        
    
          int counter = 1;
          int Numb;
          int something = 0;
             System.out.println("Please enter a letter.");
            String letters = stdin.readLine();
            
    
              while (something != 1) // does a loop while the letters dots not say peroid.
    		{
    			if (letters == ".")
    				{
    					System.out.println("You entered " + counter + "Letters");
                                            something = 1;
                                            break;
    				}
    			else
    				{
    					System.out.println("please enter another letter.");
                                            letters = stdin.readLine();
                                            counter += 1;
                                            break;
                                           
    				}
    
                      }
          }
    }


    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's because you break from the loop on line 30

    Comment

    Working...