Tag: programming

  • How to print triangle shape asterisk using for loop?

    How to print triangle shape asterisk using for loop?

    This is my first exercises on computer programming 2. To triangle shape asterisk or echo out triangle asterisk in a for loop sequence.

    ----*
    ---***
    --*****
    -*******
    *********

    Analyzing the output?

    It could be 5 line break and so on
    The number sequence of the asterisk is x = x+2

    Here is the code for the number sequence.

    $s=""; // initial variable
    $b=9; // base number of the triangle
    // execute loop if true
    for($i=1;$i< =$b;$i+=2){
    // make a line break
    $s.=$i."
    ";
    }
    echo $s;

    The output number sequences we get from the for loop

    1
    3
    5
    7
    9

    We already got the number of asterisk on each row.
    Now we can print the asterisk accordingly.

    $s=""; // initial variable
    $b=9; // base number of the triangle
    // execute loop if true
    for($i=1;$i< =$b;$i+=2){
    // store the string value of $s while the asterisk count is true
    for($j=0;$j<$i;$j++){
    $s .="*";
    }
    // make a line break
    $s.=$i."
    ";
    }
    echo $s;

    The output of triangle asterisk using for loop.

    *
    ***
    *****
    *******
    *********

    We add dash to indent the asterisk to center for the final code.

    $s=""; // initial variable
    $b=9; // base number of the triangle
    // execute loop if true
    for($i=1;$i< =$b;$i+=2){
    // store and add dash on the string value of $s while it is true
    // or $k is less than $b-$i
    for ($k=0;$k<($b-$i); $k+=2){
    $s .="-";
    }
    // store the string value of $s while the asterisk count is true
    // or $j less than $i
    for($j=0;$j<$i;$j++){
    $s .="*";
    }
    // make a line break
    $s.=$i."
    ";
    }
    echo $s;

    The output of triangle asterisk using for loop with indention.

    ----*
    ---***
    --*****
    -*******
    *********
  • HTML5 Is My New Baby

    WordStar

    What is about HTML5? Back when I was using WordStar for DOS. WordStar give me the idea how code tags works. WordStar was the first text editing software I used to print my documents. That text editor helps me to understand Hyper Text Markup Language quickly.

    I learn the basic html at the age of 16 and then I knew to myself that I love it. My first website is uploaded on GeoCities and the others from homestead. I can’t ignore that there is always something new to learn. Now that all major browsers are supporting it, I will definitely place my attention to play with the codes and start to use it.

    The code is more descriptive and very structure oriented. It will be easier to learn than previous version of html. HTML5 will surely help the loading speed and more search engine friendly because of the simplified codes.

    HTML5 Logo

    Why should I study HTML5?

    I will consider HTML5 even if old browser can’t display it properly. I know that people are more willing to upgrade their browser soon because they don’t want to miss the excitement.

    What did you learn?

    • WordStar is a rich text editor that use code tag to format the text. It runs on DOS floppy disk drive.
    • Geocites hosting is very popular free hosting in the 90’s as well as Homestead.
    • Old browser does not support HTML5.