Why won't this work as expected!?
for(int i=0;i<Nname.length;i++){
if(i><Nname.length){
System.out.print(Nname[i]+", ");
}
if(i == Nname.length){
System.out.print(Nname[i]);
}
}
Basically what I need is to display the Nname variable as many times as needed... BUT, I only want to show a comma until before the last iteration of the for loop ... so the last one is not shown with a comma... the thing is that for some reason... it does not work. Any pointers!?>
[807 byte] By [
Elvenelfa] at [2007-11-27 9:58:10]

To see this visually, in this small bit of code:
for (int i = 0; i < 5; i++)
{
System.out.println(i);
}
what is the last number printed? It's not 5 is it? So if you want to trap for the last trip through the loop, and if you are using a < condition as the final condition (not <= ), then you will need to trap for LoopMax - 1.
what happens when i == Nname.length? does the loop run? nope because it will only run when i is less than Nname.length.
By the way, as an unrelated aside, if you want to follow java naming conventions, don't name your array var Nname. It should start with a lower case letter. nName would be better.
Message was edited by:
petes1234
Thanks so much... this is my final code:
for(int i=0;i<Nname.length;i++){
if(i==Nname.length-1){
System.out.print(Nname[i]);
}else{
System.out.print(Nname[i]+", ");
}
Following your edit: Ok, I will change that asap. Thanks so much once more!
Message was edited by:
Elvenelf>