Page 1 of 1

please tell me why this 'for loop' does not work? (simple)

Posted: 30 Oct 2012 06:53
by m127
never mind; silly question

Re: please tell me why this 'for loop' does not work? (simpl

Posted: 18 Nov 2012 10:50
by Rie

Code: Select all

for (i=myVals[0];   i<Major[1];   i++)
{

  mySwitches.x[i]=1;

}
This will work but i dont think it will do what you want :)

What should this loop do? :)

Re: please tell me why this 'for loop' does not work? (simpl

Posted: 19 Nov 2012 05:41
by Macciza
Hi
Well it does work in some way - It sets mySwitches.x[45] to 1; but like Rie said What do you expect it do?
And what is the Major array?? If Major[1] is less than myVals[0] it does nothing . . .
Also 'i' never gets incremented so it won't change from it's initial value of 45 . . .

'i' gets set to 45
if 'Major[1] is less than 45 it exits
if it larger than 45 the loop runs and sets mySwitches.x[45] to 1
counter increments
if Major[2] is less than 45 it exits
if larger, the loop runs and sets mySwitches.x[45] to 1


I think you will need either a 'while' or 'do while' rather than a 'for' . ..
Also sending a small example project is often better then just sending a script . . .

MM