Does For-Loop counter stay?

Simple Question. Imagine this in ANSI-C:

int i;

for(i=0 ; i<5 ; i++){

printf("i is %d\n", i);

Will this output "i is 5" ?

Is i preserved or is the value of i undefined after the loop?


Yes. If i is declared outside of the for loop it remains in scope after the loop exits. It retains whatever value it had at the point the loop exited.

If you declatred I in the loop:

for (int i = 0 ; i < 5 ; i++)


Then i is undefined after the loop exit.

Need Your Help

Draw Textured Quad OpenGL

java opengl

I'm trying to render a quad with a texture, but it's not working.