loop error help

S

sacha_schembri

Hi im having trouble with this loop it stops at certain places but
never finiishes as it should

try {
BufferedWriter out = new BufferedWriter(new
FileWriter("file.txt",true));
for (int y = 0; y < stuobj1.stdrec.length;y++){
if (stuobj1.stdrec[1+y].equals(field1))
{y++;y++;y++;}
else
{System.out.println(y);
out.write(stuobj1.stdrec[y]);y++;
out.newLine();
out.write(stuobj1.stdrec[y]);y++;
out.newLine();
out.write(stuobj1.stdrec[y]);y++;
out.newLine();
out.write(stuobj1.stdrec[y]);
out.newLine();
out.close();
}}
} catch (IOException eee) { }
 
I

Ingo R. Homann

Hi,
> Hi im having trouble with this loop it stops at certain places but
> never finiishes as it should

- What's the data-types (stuobj etc)?
- What's the data?
- What *does* the program do?
- What do you expect it to do?

We cannot say anything to your problem if you do not provide this
information! (Although I expect that you are able to solve your problem
if you try to answer my questions...)

Oh, some things can be said:
- In most cases, it is not a good idea to modify the counter-variable of
a for-loop within the body of the loop.
- Please format your code in a readable style!

Ciao,
Ingo
 
S

sacha_schembri

Thanks anyway i fixed it i put the try...catch within the loop instead
and worked like a charm, sorry for the un formatted code but im doing
my assignment for school and we have to work in textpad cant use an IDE
and when i copied it here my formatting got messed up
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top