# Thread: why does this not work

1. ## why does this not work

I want this while loop to assign sequntial values to different array so here is what I got

Code:
int j=0;
while (j<=100)
{ for(int y=0;y<=(int)liklihood[0];y++)
{ zero[y]=j;
cout<<"\n"<<zero[y];
j++;
}
for(int y=0;y<=(int)liklihood[1];y++)
{ one[y]=j;
cout<<"\n"<<one[y];
j++;
}
for(int y=0;y<=(int)liklihood[2];y++)
{ two[y]=j;
cout<<"\n"<<two[y];
j++;
}
for(int y=0;y<=(int)liklihood[3];y++)
{ three[y]=j;
cout<<"\n"<<three[y];
j++;
}
for(int y=0;y<=(int)liklihood[4];y++)
{ four[y]=j;
cout<<"\n"<<four[y];
j++;
}
}
and it works fine but for some reason it keeps going after 100 and I have no idea why.

2. hmm, jus a guess but try

do
{

......
.....

}

while(j<100)

OR

//dunno bout this one not home to test

while(int j = 0; j<100; j++)

3. You never get back the the conditional to check j until after the 5th for loop, yet j is incremented each time through each loop. If the sum of likelihood[0] through likelihood[4] exceeds 100 then j will be greater than 100 by the time you get to the while conditional to stop the while loop.