Page 1 of 1
while loop in php
Posted: Mon May 02, 2016 10:29 am
by nokuthula
Hi
Please some one assist
Am required to use while loop ,if statement and the modulus operator together to generate the following numbers exact rows of numbers
123456789101112131416161718192021222324252627282930313233343526373840 and all they are bold
And underlined except for 10 20'30 and 40
So i must produce the same output.
Code: Select all
£i=1;
While (£i less than = 40)
(
£k=(£i%1)
If (£k==0)
(
)
£i++;
)
Re: while loop in php
Posted: Mon May 02, 2016 2:45 pm
by requinix
The modulus part isn't right - you need to check every 10th number. Otherwise you have the right code structure so far (but incorrect syntax, of course).
Did you have any specific questions about the code?
Re: while loop in php
Posted: Tue May 03, 2016 4:03 am
by nokuthula
Yes I need assistance how do I make it bold and underline
Re: while loop in php
Posted: Tue May 03, 2016 5:50 am
by requinix
Let's say you only need 1-10. Bold and underline means you're (probably) supposed to use HTML - do you know what HTML you need to generate to get
12345678910
Re: while loop in php
Posted: Tue May 03, 2016 12:25 pm
by nokuthula
I do not know I need help with the code
Re: while loop in php
Posted: Tue May 03, 2016 3:55 pm
by requinix
You know you are going to have to put some effort into this yourself, right?
Bold and underline is really simple. How about you Google how to do that in HTML?
As for your code, you will be outputting every number. Each one will be bold so that's easy. That if with the modulus: if you add an else block in there then you can use it to decide whether to show the bold version or the bold-and-underlined version of a number.
You're about three lines of code away from the solution.
Re: while loop in php
Posted: Tue May 03, 2016 8:01 pm
by Christopher
Well, the first thing you could do is convert this code to PHP:
Code: Select all
£i=1;
While (£i less than = 40)
(
£k=(£i%1)
If (£k==0)
(
)
£i++;
)
Start by getting it to loop from 1 to 40 and output the numbers. Then we can work on underlining.
Re: while loop in php
Posted: Tue May 03, 2016 9:01 pm
by nokuthula
okay thank
i will try that
Re: while loop in php
Posted: Tue May 03, 2016 10:45 pm
by Christopher
Post your actual PHP code.
Re: while loop in php
Posted: Sun May 08, 2016 2:52 am
by nokuthula
Hello
i have tried to do the output number to 40
Re: while loop in php
Posted: Sun May 08, 2016 2:53 am
by nokuthula
$i =0;
while ($i<=40){
echo"The number is ".$i."<br />";//output values from 0 to 40
$i++;
}
Re: while loop in php
Posted: Sun May 08, 2016 2:55 am
by nokuthula
$i =0;
while ($i<=40){
echo"The number is ".$i."<br />";//output values from 0 to 40
$i++;
}