Introduction [1/10]
Learn to Write Computer Programs
To begin this computer programming course, run the given program. To run the program, click on the 'Run' button.
Afterwards, click on the 'Next' button to proceed.

To run the program, click on the 'Run' button.
The editor automatically colors the source code. This feature is known as syntax highlighting.
This program consists of two statements.
The println (P-R-I-N-T-L-N) statement outputs text on the screen (println is short for print line).
The disc function draws a disc.
Exercise:
Add the statement disc( 600,150, 100 , /red );
This complex program contains many computations that produce a short animation.
The text of the entire program is called the source code. Source code usually contains many statements.
Let's make a simple modification.
Exercise:
The second statement of the source code contains the word ZedLX. Change this word to some other word. Then, run the program.
* * *
You can send this short animation to your friends by using the Share button above the source code.
You should provide your desired title of the program. You can leave other fields blank, if you like.
Then, click on the "Create Link" button to create a program link. Click on the link to see your program in action. To show your program to others, you should use the sharing buttons on the 'Execution completed' page.
This program produces a simple motion. The source code contains some unexplained features.
Let's make some simple changes to the source code.
Important:
All names are case-sensitive (purple
is not PuRpLe
nor Purple nor PURPLE).
Exercises:
1. Change the disc color to purple. Run the program.
2. The step of the for loop equals 6 (find this number). To slow down the motion, change it to number 2.
Run the program first.
A statement is a basic unit of code.
A text inside quotation marks is called a string. Strings are printed on the screen exactly as they are stated.
Besides strings, println statements can also print expressions. Expressions can use various operators like +, -, *, / .
Important:
- Plain statements must be ended by a semicolon (;) symbol.
- Parts to be printed out must be separated by a comma (,) symbol.
Exercise:
How much is 1111 * 2222 ? The star symbol is used for multiplication.
This program contains an error.
Click on the Check button to get a clue.
The computer will attempt to find out what is wrong, but it cannot always make a correct guess.
Correct the error and run the program.
Hint: The computer may sometimes produce suggestions. This time, the suggestion contains some really good advice.
Solution...
Many times, the actual error is located just before the reported one. This is one such case.
The error is in the third statement: it is missing a semicolon (;) symbol at the end.
println "Up above the world so high," ;
Operator * must be used to denote multiplication.
Round brackets (), also called parentheses, can be used to group expressions.
Square brackets [] or curly brackets {} (i.e. braces) cannot be used to group expressions.
Run the given program.
Exercise:
Add another statement to the source code to find out the result of expression
- 15*3 + 2*(90+10)
The first statement prints the number 12 followed by 7. That looks like a number 127 if the results are not separated.
A way of separating the results would be to print out some empty space in between.
Press the F11 key to enter or exit the fullscreen mode. We recommend using the fullscreen mode to make reading more pleasant. Press the F11 key again to exit the fullscreen mode.
Exercises:
1. Add the statement println "Jammed together:" , 2, 5, 1+1;
2. Add the statement println "Un-jammed: ", 2," ",5," ",1+1;
Run the given program.
This program outputs the expressions together with the results.
At the first glance, it might appear that the given strings contain expressions, but that is only an illusion. Strings cannot contain expressions.
Strings are printed out as they are stated. Expressions are evaluated before printing.
Exercise:
Add the statement println "3m × 4m = ", 3*4, "m²";
Here is another error.
Click on the Check button to see the error description.
Correct the error and run the program.
Hint: while the error report might be hard to understand this time, the computer has actually made an excellent guess.
Solution (click):
println 8 +(10 - (2+7));
<< F2:Prev - - F4:Next >>