Hello World Loop

Home

The final program in the Hello World sequence shows you how to use a loop to make the words appear many times on the screen.  A loop tells the computer to do the same things many many times.  Computers are very good at repeating tasks.  Much better than people are.  They never get bored or need to eat or stretch their legs.  They can go on for hours, and they are very fast.  In this program, we add a loop to Hello World to get the computer to write the words many times.

Program HelloWorld

    Method Main()

        Color(Blue)

        Pen(False)

        MoveTo(250, 24)

        SetFont("Times New Roman" , 28 , True , True , True)

        Loop 5

            PrintLine("Hello World")

        End Loop

    End Method

End Program

 

 

Download KPL

Since the rest of the program is the same as the one before, lets just look at the loop sequence. 

Loop 5 tells the computer to repeat everything between loop 5 and end loop the stated number of times. Try changing the number to see what happens.

We also have to change Print to PrintLine so that the computer will put each Hello World on a new line.

Loop 5

    PrintLine("Hello World")

End Loop

 

Our next program draws a star shape on the screen using KPL's drawing tools.