• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Endless loop

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Expert:
Below I have included a simple DO WHILE loop. Occasionally when I try to exit the loop it says batch file missing and re-enters the loop. I have the code from the main method as well as the output when the error occurs.

import corejava.*; //This is for the Console.read
class cyrptograph
{
public static void main (String args[])
{
char quit;
do
{
System.out.println ("Enter 1 to encode a message");
System.out.println ("Enter 2 to decode a message");
int resp = Console.readInt ("enter choice:");
if ( resp == 1)
encode();
else
decode();
String response = Console.readLine ("Enter C to continue or Q to quit");
quit = response.charAt(0);
} while (quit == 'C' | | quit == 'c');
System.out.println ("Goodbye");
} //end of main

This problem only happens periodically, but here is output I get when it happens:

Enter C to continue or Q to quit q
Goodbye
Batch file missing
C:\JavaPro\Practice\DosApp\Cryptography>
Enter 1 to encode a message
Enter 2 to decode a message
enter choice:

You can see how it prints "Goodbye" which means it has exited the DO WHILE loop, yet it somehow ends up back in the loop. Does anyone know why?

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you invoke this program? Do you use java from the command prompt?
 
Tim Barker
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I use TextPad, but I am sure I could find the same problem from the command prompt.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message "Batch file missing" is defined by yourself?
I think maybe you can convert your definition of 'char quit' to
'String quit',and do like this:
do{
........
String quit;
quit = response.subString(0,1);
........
}while(quit.equals("C") | | quit.equals("c"))
------------------
Java lover from hell!
 
Tim Barker
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes sense. I never defined "Batch file missing", but it is probably part of the Corejava that I imported. The Corejava is from the book of the same name that included a CD-ROM that allows you to input information with the Console.line command and probably took exception to how I used it. I can check the files to see if that is a exception that it throws.
Thanks
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tim Barker:
No I use TextPad, but I am sure I could find the same problem from the command prompt.


Have you tried it from the command prompt? The reason I'm asking is to find out where this "batch file" error message is coming from.
 
BWA HA HA HA HA HA HA! Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic