// First, how to write a comment :) /* There are two ways. The first line show you one. Everything you write after // is a comment as long as it's on the same line. And the second is here. */ // everything you write between /* and */ is a comment /* Variables : To create one and give it a value, you have to write something like this : */ int X = 0; // Every instruction ends with ';' char Y; Y = '0'; /* You write the type of the variable, its name, and its value. You can give it a value whenever you want. Here X is an integer, its value is 0. Y is different. It's a character. Let's say you can't do operations with variables of different types. (Actually you can convert char to int and vice versa by looking at ASCII table. But if you are looking for basic stuff, don't, or at least wait.) ) int : integer : 10 float : float : 3.1415 char : character : 'a' String : a string of characters. : "a0hello" Boolean : Something that can only be true or false. */ /* Conditions You always need tests in a program. The conditions you use are often comparisons. < strictly inferior <= inferior or equal > strictly superior >= superion or equal == equal ( the = symbol is used when you affect a value to a variable) != different */ /* For loop It's a structure where an index is defined, changes, and when it reaches a certain condition you leave the loop. Let's say I want to print in the console all the intergers from 0 to 10; */ println("First 'for' example"); for( int index = 0; index <=10; index++) {println(index);} /* I print in the console the value of 'index' index begins at 0 and reaches 10 with a step of 1. You have to place the code you execute in your loop between {} And the index++ is just a shortcut for index = index +1 You increase the value of index by 1 But you can use everything as stop condition, and change the step. */ println(""); println("Second 'for' example"); for( int i = 10; i!=0; i=i-2) {println(i);} /* the for loop you will mostly see is the first one. If you are not careful, you can sometimes miss the stop condition. In this second example, if you use a step of -3, you'll get 10, 7, 4, 1, -2, -5 ... But you'll never reach 0 and you'll stay in the loop forever. */ /* while loop with this other kind of loop, you just specify the condition to stay in the loop */ println(""); println("'while' example"); int i=0; while(i<10) {i++; println(i);} // BE CAREFUL WITH THIS // In the for loop, the index changes automatically. Here, you have to add // the i++ in the code executed in the loop. // When I was writing this, I forgot, I got stuck in the loop. Processing crashed. // I didn't save... /* if / else / else if if something is true, then i do... if (condition) { I do this } */ int x=0; int y=2; int z=0; if (x==y) {println("x is equal to y");} else if (x==z) {println("x is equal to z");} else if (y==z) {println("y is equal to z");} else {println("x, y and z are different");} /* you test every condition you want with if else if else if ... The 'else' at the end represent all the other cases. */