Can not get loop to count
Please help. I have seen tons of posts similar to this but have not been able to find the solution. A simple bit of code that works in Perl, C#, C++, but not Java.
int i = 1;
if (grp !=null){
bwGrp.write(i +": " + grp +"\r\n");
i++;
}
Out put is ALWAYS 1: groupname
I would like it to count so that I know how many lines are written.
Thanks,
Elliott
[615 byte] By [
nilSatisa] at [2007-10-3 3:34:27]

> Please help. I have seen tons of posts similar to
> this but have not been able to find the solution. A
> simple bit of code that works in Perl, C#, C++, but
> not Java.
>
> >int i = 1;
> if (grp != null){
>
> rp.write(i + ": " + grp + "\r\n");
> i++;
>
>
> Out put is ALWAYS 1: groupname
> I would like it to count so that I know how many
> lines are written.
> Thanks,
> Elliott
It's not a loop.
while (grp != null) {
rp.write(i + ": " + grp + "\r\n");
i++;
}
will result in either no print or an endless loop, because nothing about gpr is changing. Perhaps you want:
for (int i = 0; i < grp.length; i++) {
if ( grp[i] != null )
rp.write(i + ": " + grp[i] + "\r\n");
}
Thanks abillconsl Your right, my brain was not working properly, too much coding driving me insane!I put the increment in the proper location and it works fine...