Page 1 of 1

Need a help - PHP cording (for my exercise)

Posted: Fri May 11, 2012 2:03 pm
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

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

Posted: Fri May 11, 2012 2:07 pm
by Celauran
We're not going to do your homework for you. What have you written so far? Where are you running into trouble?

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

Posted: Sat May 12, 2012 3:28 am
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;
}

?>