View Single Post
Old 08-08-2011, 11:29 AM   #3
sharma.s.prakash
Senior Member
 
sharma.s.prakash's Avatar
 
Join Date: Aug 2011
Posts: 110
Smile yah i m agreed

yah these are the common example. when at the begining of any programming these are vary use full so that any can know how to manipulate loops whats the effect on out put if any changes are done some variation are applied.These are important at the beginning of programming.

can also try this to make diamond shape

PHP Code:
for($n=1;$n<=9;$n++) {
    for(
$s=1;$s<=20-$n;$s++) {
        echo 
" "// "&nbsp";
    
}
    for(
$m=1;$m<=$n;$m++) {
        echo 
$m.' '//echo $m.'&nbsp;';
    
}
    echo 
"\n"//echo "<br>"; 
}
for(
$n=8;$n>=1;$n--) {
    for(
$s=1;$s<=20-$n;$s++) {
        echo 
" "// "&nbsp";
    
}
    for(
$m=1;$m<=$n;$m++) {
        echo 
$m.' '//echo $m.'&nbsp;';
    
}
    echo 
"\n"//echo "<br>"; 

output
Code:
	           1 
                  1 2 
                 1 2 3 
                1 2 3 4 
               1 2 3 4 5 
              1 2 3 4 5 6 
             1 2 3 4 5 6 7 
            1 2 3 4 5 6 7 8 
           1 2 3 4 5 6 7 8 9 
            1 2 3 4 5 6 7 8 
             1 2 3 4 5 6 7 
              1 2 3 4 5 6 
               1 2 3 4 5 
                1 2 3 4 
                 1 2 3 
                  1 2 
                   1

Last edited by sharma.s.prakash; 08-08-2011 at 11:54 AM.
sharma.s.prakash is offline   Reply With Quote