Пример #1
0
            //adds 1 do $dotlocation
            $col = $col - 1;
            //subtracts 1 from $col
            print_r("\n");
            //print line break
        }
        //begin outer loop again - note the new values of $col $dotlocation $i $j and $d
        print_r("\n");
    }
    function UpsideDownTriangle()
    {
        $col = 5;
        //starts the columns at 5
        for ($i = 0; $i <= 5; $i++) {
            //iteration for the "rows" loop - if $i <= 5 move to nested loop and add 1 to $i
            for ($j = 0; $j <= $col; $j++) {
                //iteration for the "columns" loop - if $j <= $col print "." and add 1 to $j. run loop until false.
                print_r(".");
            }
            $col = $col - 1;
            //subtracts one from $col when the nested loop is false.
            print_r("\n");
            //prints line break & returns to original loop, note new values for variables.
        }
    }
}
$printShape = new ShapeMaker(4);
//creates a variable calling class
$printShape->Triangle();
$printShape->BackwardsTriangle();
$printShape->UpsideDownTriangle();
Пример #2
0
        $col = 3;
        $starcount = 0;
        for ($i = 0; $i <= 3; $i++) {
            for ($c = 0; $c <= $col; $c++) {
                print_r(" ");
            }
            for ($j = 0; $j <= $starcount; $j++) {
                print_r("*");
            }
            $starcount = $starcount + 1;
            $col = $col - 1;
            print_r("\n");
        }
    }
    function UpsideDownTriangle()
    {
        $col = 3;
        for ($i = 0; $i <= 3; $i++) {
            for ($c = 0; $c <= $col; $c++) {
                print_r("*");
            }
            $col = $col - 1;
            print_r("\n");
        }
    }
}
$mySC = new ShapeMaker(4);
// calls function
$mySC->Triangle();
$mySC->BackwardsTriangle();
$mySC->UpsideDownTriangle();