473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1.  public class J12Q5
  2. // counting letters
  3. {
  4.     public static void main(String[]args) throws IOException
  5.         {
  6.             InputStreamReader inStream = new InputStreamReader(System.in);
  7.         BufferedReader stdin = new BufferedReader(inStream);
  8.  
  9.  
  10.       int counter = 1;
  11.       int Numb;
  12.       int something = 0;
  13.          System.out.println("Please enter a letter.");
  14.         String letters = stdin.readLine();
  15.  
  16.  
  17.           while (something != 1) // does a loop while the letters dots not say peroid.
  18.         {
  19.             if (letters == ".")
  20.                 {
  21.                     System.out.println("You entered " + counter + "Letters");
  22.                                         something = 1;
  23.                                         break;
  24.                 }
  25.             else
  26.                 {
  27.                     System.out.println("please enter another letter.");
  28.                                         letters = stdin.readLine();
  29.                                         counter += 1;
  30.                                         break;
  31.  
  32.                 }
  33.  
  34.                   }
  35.       }
  36. }
  37.  


Thanks
May 26 '15 #1

✓ answered by Rabbit

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

1 1398
Rabbit
12,516 Expert Mod 8TB
It's because you break from the loop on line 30
May 26 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Glen Wheeler | last post by:
Hello All. I've been coding in python for a reasonable amount of time now (coding in total for approx. 20 years) and am writing a performance intensive program in python. The problem I'm having...
1
by: Brian Burgess | last post by:
Hi, Any one know how to go to the beginning of the Next iteration of a For Loop? Similar to a c-style 'continue'? Many thx in advance.. -BB
4
by: David Dvali | last post by:
What is loop continue in VB? Loke in C#: for (int i=0; i<10; i++) { if (i==7) continue; ... }
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
1
by: Danny M | last post by:
What i want to do is this: I have a loop of records. For some records the user need to give some feedback Because of this i want to open a modal form in the loop When the user clicks a button...
25
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
8
by: Nasutperaah | last post by:
Hi all, I have written a C ++ program and now need to add a way to make it exit on command, or start over from the beginning. I have very little programming knowledge; Here is my code: Thanks in...
2
by: lSugaRushl | last post by:
Hey all. New to the forum. Is there a way to make a loop continue until an input is entered? i've tried the - if (cin.peek() == '\n') {} - but it stays there til an input is added, just...
3
by: Yess | last post by:
I'm trying to implement a function which will print all all the diferent type of products and their makes. I have 3 types of products and 6 makes. The problem is, it only prints one type of product 1...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.