> -----Original Message----- > From: Stephen [mailto:[EMAIL PROTECTED]] > Sent: 11 December 2002 02:50 > > I want to repeat the following code as many times as the user > specifies in the variable $_POST['x']. I then need to have > the output display as all the numbers found in the sequence. > How would I do this? > > Code: > > $number = 1; > $output = $num3; > do { > $output = $output * $r . ", ";
Well, the first time you do this you no longer have a number but a string, so you're already in trouble.... > $number++; > } while($number < $_POST['x']); > > What this is supposed to do is find the next X numbers in a > sequence with the common ratio (r) being the multiplier. > After that, it puts it in a list, and tells the user the next > X numbers in the sequence... Why don't you just echo each number as you calculate it? Whilst we're about it, let's use a for loop instead of that cumbersome do while! for ($output = $num3, $number = 1; $number < $_POST['x']; $number++): $output *= $r; echo "$output, "; endfor; If you need to build the string for other purposes, you will need to build it up in a separate variable: for ($list='', $output=$num3, $number=1; $number < $_POST['x']; $number++): $output *= $r; $list .= ($list?', ':'') . $output; endfor; echo $list; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php