# Using 'for' loops

**URL:** <https://forum.kirupa.com/t/using-for-loops/12978>\
**Category:** Uncategorized\
**Created:** [February 6, 2003, 11:10pm UTC](https://forum.kirupa.com/t/using-for-loops/12978 "2003-02-06T23:10:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojoNYC](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mojoNYC](https://forum.kirupa.com/u/mojoNYC)\
**Post date:** [February 6, 2003, 11:10pm UTC](https://forum.kirupa.com/t/using-for-loops/12978/1 "2003-02-06T23:10:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2003, 11:44pm UTC](https://forum.kirupa.com/t/using-for-loops/12978/2 "2003-02-06T23:44:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2003, 11:52pm UTC](https://forum.kirupa.com/t/using-for-loops/12978/3 "2003-02-06T23:52:12Z")

</div>

> \*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:

```auto

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);
	}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 12:02am UTC](https://forum.kirupa.com/t/using-for-loops/12978/4 "2003-02-07T00:02:45Z")

</div>

this is the code:

```php
	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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 1:00am UTC](https://forum.kirupa.com/t/using-for-loops/12978/5 "2003-02-07T01:00:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 2:45am UTC](https://forum.kirupa.com/t/using-for-loops/12978/6 "2003-02-07T02:45:49Z")

</div>

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)];
