Page 1 of 1

How to bold and underline specifit number using FOR LOOP

Posted: Mon Apr 18, 2016 7:24 am
by lezy
FHello everyone,

Please how can I use for loop to generate the following numbers exactly:

12345678910111213141516171819202122232425262728293031323334353637383940.

I used the following codes but not working as expected:

Code: Select all

for ($i = 1; $i < 40; $++)
{
echo $i. '<b>'<u>'.$i. '</b>'<.u>';
Thanks.

Re: How to bold and underline specifit number using FOR LOOP

Posted: Mon Apr 18, 2016 7:43 am
by Celauran
That's not even a complete loop. What are you actually trying to do?

Re: How to bold and underline specifit number using FOR LOOP

Posted: Mon Apr 18, 2016 1:20 pm
by Christopher
So something like the below will work. Since you appear to want to highlight every 10th value starting at 15, I changed the values to multiples of 10 (i.e., $i - 5) and then checked the remainder of that by dividing by 10 to see if was a multiple of 10.

Code: Select all

for ($i = 1; $i < 40; ++$i) {
	if (($i >= 15) && (($i - 5) % 10 == 0)) {
		echo "<b><u>$i</b></u> ";
	} else {
		echo "$i ";
	}
}

Re: How to bold and underline specifit number using FOR LOOP

Posted: Wed Apr 20, 2016 8:07 am
by lezy
Hi Christopher,

Thanks for your assistance.

The codes you gave did exactly what I want.

Thanks once again.