Need a help - PHP cording (for my exercise)

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
Iroshw
Forum Newbie
Posts: 1
Joined: Fri May 11, 2012 1:58 pm

Need a help - PHP cording (for my exercise)

Post by Iroshw »

Hi,

I'm new to this Forum. I need to find the correct answers for following questions.

Exercise:
write down PHP code to print all ODD numbers between 0 and 100.
a) Using for loop
b)Using while loop

Exercise:
Define a PHP function to get a positive integer as input as input parameter and to return the sum of all integers from 1 up to that number

iroshw@live.com
Irosh
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need a help - PHP cording (for my exercise)

Post by Celauran »

We're not going to do your homework for you. What have you written so far? Where are you running into trouble?
almossaid
Forum Newbie
Posts: 13
Joined: Sat Feb 25, 2012 11:27 am

Re: Need a help - PHP cording (for my exercise)

Post by almossaid »

Try this
while loop

Code: Select all

<?php
$Count = 1;
while ($Count < 100) {
echo "$Count ";
$Count = $Count+1; 
}
?>
for loop

Code: Select all

<?php
for ($i = 1; $i < 100; $i++) {
    echo $i;
}

?>
Post Reply