In FOR loops

 

I have just found out someting interesting writing a script.
This is about a variable i in a loop.

Example :
  Given a function drawObject(x,y) with
     for ( i = 1; i < n+1; i++)
     { // code which acts with i }

In onLoad(), I have written a loop to draw 10 objects calling drawObject :
for ( i = 0; i < 10; i++)
{ // code to reckon x et y (depends on i )
    // then call drawobject(x,y)
}
We yield only 1 object instead of 10 !

Why ? I don't know I put a finger on it but I have fixed up the trouble with a different name of the variable in one loop.
For instance, for ( j = 1; j < n+1; j++) in drawObject
Yet, these loops are not included, but it acts as if. Bug, huh ?
Coming from C++ and PHP world, it's a tough time.

 


Si vous aimez le site

 

Select a language if you need :


Page chargée en 0.004 sec.

Dernière Modification : Mer 25 Janvier 2017 8:56
Copyright © 1999-2017 Jean-Paul Molina Tous droits réservés.

to Google