I dun quite understand how this program works.......
What is the output of this program?

``````<html>
<!-- test01.php -->
<body>

<?php
\$x = 2;
for (\$i = 1; \$i <= 6; \$i++)
{
if (\$i % 2 == 1)
{
\$x++;
}
print \$i . 'x' . \$i * \$x . " ";
}

?>

</body>
</html>

*******

1x3  2x6  3x12  4x16  5x25  6x30``````

Thanks,

Tony

3
Contributors
9
Replies
10
Views
8 Years
Discussion Span
Last Post by diafol

This sounds like a homework problem to me, maybe you should to a little more studying. Why else would you include the "answer."

This sounds like a homework problem to me, maybe you should to a little more studying. Why else would you include the "answer."

This is an example of the kind of question that might appear in the final exam and although I have done 4 weeks of PHP, I dun quite get the reason for the output, which was given by my prof...

You've spent more time on daniweb than hitting your books. Not a bad thing to do, but you need to do your own work now.

Clue: what type of numbers does \$i % 2 == 1 give you??

You've spent more time on daniweb than hitting your books. Not a bad thing to do, but you need to do your own work now.

Clue: what type of numbers does \$i % 2 == 1 give you??

I guess, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, etc...
Am I correct?

Give the man a cigar! Now work out the relationship to the output or series. Oops almost gave it away.

Give the man a cigar! Now work out the relationship to the output or series. Oops almost gave it away.

X = 2 rite,
Then howcome the answer to the code is:
1 x 3, 2 x6, 3 x 12, 4 x16, 5 x 25, 6 x30

x++(shouldn't it be 3, 5, 7, 9, 11, 13)

I am confused...

X = 2 rite,
Then howcome the answer to the code is:
1 x 3, 2 x6, 3 x 12, 4 x16, 5 x 25, 6 x30

x++(shouldn't it be 3, 5, 7, 9, 11, 13)

I am confused...

Mais non, mon cheri.

You always admire what you really don't understand

It would be wrong of me to arrest your admiration.

Mais non, mon cheri.

It would be wrong of me to arrest your admiration.

Could you please help me one last time on this, I am really lost...

Thanks,

Tony

Paid รข bod yn wirion, gwranda, rwyt wedi derbyn sawl darn o god yn rhad ac am ddim, cer i wneud gwaith dy hun.

In a word, no.

I think your semester average has been bumped enough already. You get the grades you deserve at the end.

False dawns and dead ends are the making of men. What feeble excuse of a man shall you turn out to be if you continue to complete a crossword by first checking the answers?

Go forth and pound thy books.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.