473,508 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why doesn't my loop continue

3 New Member
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
1 1400
Rabbit
12,516 Recognized Expert Moderator MVP
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
2598
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
14694
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
4827
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
2554
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
1243
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
18350
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
29110
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
2053
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
1869
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...
0
7233
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
7410
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...
1
7067
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
7505
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
5650
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
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.