Introduction [1/10]
Learn to Code, Here and Now
To begin the 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 source code of this program consists of two statements, each in its own line.
The editor automatically colors the source code. This feature is known as “syntax highlighting”.
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 one more statement to the program: disc( 600,150, 100 , /red );
This complex program requires many computations to produce a short animation.
[Run the program]
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 can use the sharing buttons on the “Execution completed” page.
Run the program first.
In the computer programming jargon, “to print out” actually means “to output on the screen”.
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.
This program contains an error.
Click on the Check button to get a clue.
The automatic verifier 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 verifier 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.
[Run the program]
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.
Exercise:
Display 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.
[Run the program]
A way of separating the results would be to print out some empty space in between.
We recommend using the fullscreen mode to make reading more pleasant. Press the F11 key to enter the fullscreen mode. Press the F11 key again to exit the fullscreen mode.
Exercises:
1. Add a statement: println "Jammed together:" , 2, 5, 1+1;
2. Add a statement: println "Un-jammed: ", 2," ",5," ",1+1;
This program outputs the expressions together with the results.
[Run the program]
At 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 a statement: println "3m × 4m = ", 3*4, "m²";
This program contains an error.
Click on the Check button to see the error description.
Correct the error, then run the program.
Hint: while the error report might be hard to understand this time, the automatic verifier has actually made an excellent guess.
Solution (click):
println 8 +(10 - (2+7));
This program produces a simple animation.
The source code contains many unexplained features.
[Run the program]
Let's make some small 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. In the source code of this program, the number 6 is
the step of the for loop.
Change the number 6 to number 2 in order to slow down the motion.
[Run the program]
<< F2:Prev - - F4:Next >>