Goto Loop
When first exploring the Basic language for any computer, a loop is one of the best things to do for getting an instant result on the screen. The Commodore 64 Basic program example below shows this in action.
10 PRINT”HELLO WORLD!!!”
20 GOTO10
For Loop
The next example is a step up from the first. Here you will learn how to cycle through a series of numbers to display character set data within our Commodore 64 Basic program example. The CHR$ is pronounced as “Character String”.
10 FORX=0TO255
20 PRINTCHR$(X);
30 NEXT
Clear Screen
The Commodore 64 contains a character that provides a full swipe of the screen to remove all the data that exists.
10 PRINT CHR$(147)
Printing PET ASCII Characters
The program below provides an example of showing how to use the control key to display an assortment of interesting characters on the screen.
20 PRINT”
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”
Print middle data in a String
Using the command MID$ (stands for “middle string”) will allow you to extract individual characters from a String and show them on the screen.
30 DIM A$(20)
40 A$(1)=”STEVE MORROW”
50 PRINTA$(1)
60 REM PRINT SECTION OF A STRING
70 T$=MID$(A$,1,3)
80 PRINTT$
Loop through full data in a String
Let’s append to the program and create a For loop that shows how to print through a string from all the data that exists to the last remaining character.
90 FORX=LEN(A$) TO 1 STEP -1
100 PRINT MID$(A$,1,X)
110 NEXT
Print the string backwards
Using a command called LEN (length) allows you to read the length of the specified String. In this example it prints the String “A” backwards making the new changes below.
90 FORX=LEN(A$) TO 1 STEP -1
100 PRINT MID$(A$,X,X);
110 NEXT
The INPUT statement defined
The new program shows how to use a new command called INPUT, which can store characters you type at a prompt and wait for you to press the Return key. The data is saved in a String that can be reproduced to the screen or utilized by a Commodore 64 Basic program example.
10 PRINT CHR$(147)
20 POKE53280,11:POKE53281,7
30 DIM A$(20)
40 A$=”STEVE MORROW”
60 REM PRINT SECTION OF A STRING
70 T$=MID$(A$,1,5)
80 PRINT T$
85 INPUT”TYPE A WORD PLEASE”;W$
90 FORX=LEN(W$) TO 1 STEP -1
110 PRINT MID$(W$,X,1);
110 NEXT
120 INPUTNM$
Display the left or right part of a String
The next Commodore 64 program demonstrates how to pull data characters from the left or right side of the entered String.
130 PRINT
140 REM HOW LEFT/RIGHT WORKS
150 PRINT LEFT$(W$,3)
160 PRINT RIGHT$(W$,3)