By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

use for loop

P: 1
Dear,

I want this type of output

* * * * * * * *
* * * * * *
* * * *
* * *
*
* * *
* * * *
* * * * * *
* * * * * * * *
Regards
Pawan Kumar
919999823227
Feb 7 '08 #1
Share this Question
Share on Google+
2 Replies


rpnew
100+
P: 188
Dear,

I want this type of output

* * * * * * * *
* * * * * *
* * * *
* * *
*
* * *
* * * *
* * * * * *
* * * * * * * *
Regards
Pawan Kumar
919999823227
Hi,
I came up with this......
[PHP]
<?php
for($i=8;$i>0;)
{
for($j=$i;$j>0;$j--)
{
//echo $i;
echo " *";
}
if($i<4) echo " *";
echo "<br>";
$i=$i-2;

}
for($i=0;$i<10;)
{
for($j=$i;$j>0;$j--)
{
//echo $i;
echo " *";
}
if($i<4) echo " *";
echo "<br>";
$i=$i+2;

}
?>
[/PHP]

Regards,
RP
Feb 8 '08 #2

Markus
Expert 5K+
P: 6,050
Hi,
I came up with this......
[PHP]
<?php
for($i=8;$i>0;)
{
for($j=$i;$j>0;$j--)
{
//echo $i;
echo " *";
}
if($i<4) echo " *";
echo "<br>";
$i=$i-2;

}
for($i=0;$i<10;)
{
for($j=$i;$j>0;$j--)
{
//echo $i;
echo " *";
}
if($i<4) echo " *";
echo "<br>";
$i=$i+2;

}
?>
[/PHP]

Regards,
RP
I like.
I was striving trying to figure out some logic to make this pattern.. needless to say i couldn't.

:(
Feb 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.