while loop in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

while loop in php

Post 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++;
)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: while loop in php

Post 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?
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

Yes I need assistance how do I make it bold and underline
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: while loop in php

Post 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
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

I do not know I need help with the code
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: while loop in php

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: while loop in php

Post 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.
(#10850)
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

okay thank

i will try that
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: while loop in php

Post by Christopher »

Post your actual PHP code.
(#10850)
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

Hello

i have tried to do the output number to 40
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

$i =0;

while ($i<=40){
echo"The number is ".$i."<br />";//output values from 0 to 40
$i++;
}
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: while loop in php

Post by nokuthula »

$i =0;

while ($i<=40){
echo"The number is ".$i."<br />";//output values from 0 to 40
$i++;
}
Post Reply