[A89] Re: c code problem...


[Prev][Next][Index][Thread]

[A89] Re: c code problem...




>
> What is the difference betweent these two snippets of code? That is, why
> doesn't the while loop output the same thing as the for loop?
>

That might sound like a silly question, but why do you expect those to be
the same ? You are performing one more test in the first one, and don't
perform the same things at the same moment...




> for((*count)=1; (*count)<=52+8; (*count)++) // loop no more than 60 times
> {
>     if(cards_placed[(*count)]==0)  // if we've come to the end of the
stack
>         (*zero)++;          // increment the counter
>     if((*zero)==tempx)       // if we have looped enough
>         break;            // break out of the loop
>     if((cards_placed[(*count)]==0) && ((*zero)!=tempx)) // if we finished
> the stack
>         (*py)=-2;           // reset the y coordinate variable
>     (*py)++;            // increase it
> }
>
> ...and...
>
> (*count)=1;
> while((*zero)!=tempx)
> {
>     if(cards_placed[(*count)]==0)
>         (*zero)++;
>     if((cards_placed[(*count)]==0) && ((*zero)!=tempx))
>         (*py)=-2;
>     (*py)++;
>    (*count)++;
>   }
>
> Thanks...
>
>
>
>
>





References: