Author: Michel Langeveld
Date: 13:56:21 12/27/01
Go up one level in this thread
On December 27, 2001 at 11:16:20, José Carlos wrote:
>On December 27, 2001 at 09:11:23, Michel Langeveld wrote:
>
>>On December 27, 2001 at 09:02:00, José Carlos wrote:
>>
>>>
>>> When things like these happen, I don't know whether it is the compiler that
>>>doesn't work or I'm losing my mind. Yesterday I added this piece of code:
>>>
>>>for (i=0;i<PosActual->NumPeonesB;i++)
>>>{
>>> cCol=Columna(g_iPL_PB[i]);
>>> cFil=Fila(g_iPL_PB[i]);
>>> if (cFil>Retrasado(uPeonesB[cCol]))
>>>uPeonesB[cCol]=(ParteAvanzada(uPeonesB[cCol]))|(unsigned int)(cFil);
>>> if (cFil<Avanzado(uPeonesB[cCol]))
>>>uPeonesB[cCol]=(cFil<<16)|ParteRetrasada(uPeonesB[cCol]);
>>>}
>>>for (i=0;i<PosActual->NumPeonesN;i++);
>>
>>You have an ; after the for. This probably not what you want.
>
> A typo, sorry. It's not in my code. I removed the comments before posting the
>code here and placed that ; for error.
>
>>>{
>>> cCol=Columna(g_iPL_PN[i]);
>>> cFil=Fila(g_iPL_PN[i]);
>>> if (cFil<Retrasado(uPeonesN[cCol]))
>>>uPeonesN[cCol]=(ParteAvanzada(uPeonesN[cCol]))|(unsigned int)(cFil);
>>> if (cFil>Avanzado(uPeonesN[cCol]))
>>>uPeonesN[cCol]=(cFil<<16)|ParteRetrasada(uPeonesN[cCol]);
>>> i++;
>>>}
>>
>>And about the counter
>>for (int i=0; i<7; i++)
>>{
>> cout << i << endl;
>>}
>>
>>cout << i << endl;
>>
>>means that the counter printed is 7 at last.
>>In my opinion it's better not to rely i = 7 and make your code robust.
>
> I don't understand this. I want to loop through the pawn list. I have 8 pawns,
>so I loop between 0 and 7 (i<8). What do you mean? Better to write i<=7 instead?
>
> José C.
Although I think the problem you posted before is already solved I still answer
your question. It's good to write:
int i;
for (i=0; i < 8; i++)
{
/* i = 0,1,2,3,4,5,6,7 here */
}
/* i = 8 here */
But you have to consider that if you use this construction that after this for
i=8 in the end.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.