# Printing 2^1, 2^2, 2^3, 2^4 and 2^5

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi,

When I use a while loop, the output is: 2 4 8 16 32, as desired:

<?php

\$c=1;
while(\$c<=5) {
\$d = newpow(2, \$c);
print "\$d ";
\$c++;
}

function newpow(\$base, \$power) {
// statements...
}
?>

The But when I use a for loop, the output is: 64:

<?php

for(\$c=1; \$c<=5; \$c++);
{
\$d = newpow(2, \$c);
print "\$d ";
}

function newpow(\$base, \$power) {
// statements...
}
?>

Why is this??

Many thanks,

Michael

## Re: Printing 2^1, 2^2, 2^3, 2^4 and 2^5

mejpark wrote:

[...]

Here your loop ended right at the ;

After the loop comes this:

Heiko

--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage

## Re: Printing 2^1, 2^2, 2^3, 2^4 and 2^5

That's great, thanks.  I can't believe I didn't catch that!

Regards,

Mike

## Re: Printing 2^1, 2^2, 2^3, 2^4 and 2^5

That's great, thanks.  I can't believe I didn't catch that!

Regards,

Mike