cant make a for loop without declaring beforehand the variable i am using as the counter

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
diniz
Posts: 5
Joined: May 4th, 2020, 11:28 pm

cant make a for loop without declaring beforehand the variable i am using as the counter

Post by diniz » June 24th, 2020, 2:57 pm

so i know i have a lot to learn but its really pissing me of that i cant make a for loop like this run

Code: Select all

for(i == 0;i < n; i ++){
gfx.PutPixel(x + n, y, Colors::Blue);
}
but if i do like this it works

Code: Select all


int i;

for(i == 0;i < n; i ++){
gfx.PutPixel(x + n, y, Colors::Blue);
}
as far as i know i shoudnt need to declare that "i" variable and the for loop should declare it by itself so whats going on?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: cant make a for loop without declaring beforehand the variable i am using as the counter

Post by albinopapa » June 24th, 2020, 6:54 pm

Code: Select all

for( int i = 0; i < n; ++i ){
    gfx.PutPixel( x + i, y, Colors::Blue );
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Post Reply