Strings
There are certain types of data (or information) called "strings." Strings contain a sequence of characters (letters, numbers, and symbols) enclosed in quotation marks. For example, "Hello World!" is a string.
With the PRINT command, you can also print numbers to the screen. Delete the current program (unless you already have) and write the following:
<press Enter>
Press F5 to run the program. The program outputs:
Expressions
An expression is something the interpreter calculates (or evaluates). Such as:
1 + 1 (returns 2)
100 - 47 (returns 53)
3 * 34 (returns 102)
80 / 4 (returns 20)
(100 * 3) + 56 (returns 356)
NOTE: The asterisk (*) means to multiply two numbers; the slash (/) means to divide.
If you pass an expression to the PRINT command, the value returned (a number) is printed.
Clear the current program, and then run the following:
PRINT 512 + 478
Program output:
990
If you enclose the expression with quotation marks, the expression becomes a string and isn't evaluated. For example:
PRINT "512 + 478"
Output:
512 + 478
More about the PRINT command
You can use multiple print statements in your program.
PRINT "Hello"
PRINT "World"
Output:
Hello
World
To place World onto the previous line, place a semi-colon after PRINT "Hello".
PRINT "Hello";
PRINT "World"
Output:
HelloWorld
Also, if you put a space before the strings on the first line, the program will insert spaces between the two words.
PRINT "Hello ";
PRINT "World"
Output:
Hello World
What you learned in Tutorial 3
1. Strings
2. Expression
3. Print (continuation)
Follow @Elitcode on Twitter
What you learned in Tutorial 3
1. Strings
2. Expression
3. Print (continuation)
Follow @Elitcode on Twitter
No comments:
Post a Comment