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
having a really hard time figuring something out
Page 1 of 110 Replies - 228 Views - Last Post: 06 October 2012 - 06:05 AM
Replies To: having a really hard time figuring something out
#2
Re: having a really hard time figuring something out
Posted 05 October 2012 - 10:11 PM
Huh? When is then? When does it repeat?
#3
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
and I cannot remember how to do this
#4
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?
#5
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
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
#6
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;
}
#7
Re: having a really hard time figuring something out
Posted 05 October 2012 - 10:35 PM
thanks I got it working
#8
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
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>
#9
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.
#10
Re: having a really hard time figuring something out
Posted 05 October 2012 - 10:58 PM
what should it be then?
#11
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.";
}
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|