10 Replies - 500 Views - Last Post: 06 October 2012 - 06:05 AM Rate Topic: -----

#1 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

having a really hard time figuring something out

Posted 05 October 2012 - 10:06 PM

I just had a brain fart and for the life of me cannot remember how to get a for loop to count first by 3 then 2 and repeat
Is This A Good Question/Topic? 0
  • +

Replies To: having a really hard time figuring something out

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:11 PM

Huh? When is then? When does it repeat?
:blink:
Was This Post Helpful? 0
  • +
  • -

#3 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:15 PM

I want to have a for loop first count by 3 and after that 3 count by 2 then by 3 then by 2 and so on untill it reaches 238

and I cannot remember how to do this
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:17 PM

Ok, I'll try again. When do you want it to stop counting by 3? When would it stop counting by 2?
Was This Post Helpful? 0
  • +
  • -

#5 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:24 PM

the very first time it counts I want it to stop counting by 3 but then start counting by 2 but after that 2 start counting by 3 again etc...

I know this is possible in javascript but I don't want to go through the proccess of setting up the javascript to do this
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:28 PM

I'd use an array. This is in C, but you should be able to do it easily in PHP:
	int incr[2] = {2,3};
	int cnt = 0;
	
	for (int i = 1; i < 238; i+= incr[cnt]) {
		cout << i << endl;
		cnt++;
		cnt %= 2;
	}


Was This Post Helpful? 2
  • +
  • -

#7 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:35 PM

thanks I got it working
Was This Post Helpful? 0
  • +
  • -

#8 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:46 PM

you can see what I was working on here http://the-test.como.../color-test.php

the code
<html>
<head>
<style type="text/css">
div {
width: 100%;
height: 5px;
}
</style>
</head>
<body>
Black <br /><br />
<?php
$incr = array("2","3");
$cnt = 0;
for ($i = 0; $i <= 255; $i+= $incr[$cnt]) {

echo '<div style="background-color: rgb('.$i.','.$i.','.$i.');"></div>';

$cnt++;

$cnt %= 2;
}
?>
<br />
<br />
To White
<br /><br /><br />
Black<br /><br />
<?php
for($i = 0;$i <= 255;$i++){
  echo '<div style="background-color: rgb('.$i.',0,0);"></div>';
}
?>
<br />
<br />
To Red
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:50 PM

Why is $incr an array of strings? Sure, PHP will let you get away with it, but it's still wrong.
Was This Post Helpful? 1
  • +
  • -

#10 jack13580  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-October 11

Re: having a really hard time figuring something out

Posted 05 October 2012 - 10:58 PM

what should it be then?
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: having a really hard time figuring something out

Posted 06 October 2012 - 06:05 AM

Usually when you want to use a number you use numbers and not strings.
$x = "1" ;
$y = 1;
if($x === $y) {
  echo "They're equal and of the same type.";
} else {
  echo "They're either not equal or not of the same type.";
}

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1