# Using 'for' loops

i know/think i’ve seen this somewhere, but how do you make a ‘for’ loop using 3 variables and have as go thru the script each time using the next var in the list, something like this:

pseudocode:
(for x, y, z; condition; incr){
1st time: x = function(x);
2nd time: y=function (y);
3rd time: z=function(z);
}

does this make sense?
-mojo

I don’t think it’s possible… But if it is…

I’m guessing it would look like this then:

for(x=1,y=1,z=1;x<5,y<5,z<5;x++,y++,z++)

Dunno though man… Gonna have to check it out.

*Originally posted by mojoNYC *
**

pseudocode:
(for x, y, z; condition; incr){
1st time: x = function(x);
2nd time: y=function (y);
3rd time: z=function(z);
}

does this make sense?
-mojo **

thats not really explaining enough. Wheres the incr in all this? How are x y and z effected? If you just want to alternate through the variables as you progress through the loop you can use something like this:

``````
for (i=0; i< 10; i++){
switch(i%3){
case 0: x=function(x); break;
case 1: y=function(y); break;
case 2: z=function(z);
}
}

``````

this is the code:

``````	R=parseInt(myHex.slice(0,2),16);
B=parseInt(myHex.slice(4,6),16);
G=parseInt(myHex.slice(2,4),16);
RHex=HexTable[R];
GHex=HexTable[G];
BHex=HexTable**;
``````

as you can see it ain’t much, but i’m on a huge kick of trying to break all my code down as far as possible–is it even worth the effort to save 4 lines?

It’s not worth it man…

Half the time… Shortening your code like that can just screw up your cod… And then you have to spend some time to just fix it… Just use 3 loops if need be and go with it like that…

Peace

what are you looping through??

one way to shorten what you have there is just cutting out the R,G and B ‘middle man’ variables.

RHex=HexTable[parseInt(myHex.slice(0,2),16)];
GHex=HexTable[parseInt(myHex.slice(4,6),16)];
BHex=HexTable[parseInt(myHex.slice(2,4),16)];