To begin I have found the definition for the 'if' statement on processing....................
| Name | if |
|---|---|
| Examples | ![]() for (int i=5; i < height; i+=5) {
stroke(255); //Set the color to white
if(i < 35) { //When "i" is less than "35"...
stroke(0); //...set the color to black
}
line(30, i, 80, i);
} |
| Description | Allows the program to make a decision about which code to execute. If the test evaluates to true , the statements enclosed within the block are executed and if the test evaluates to false the statements are not executed. |
| Syntax |
if (test) {
statements
} | ||||||||
| Parameters |
|
I next found the definition for 'else' statement on processing............
| Name | else | |||||||
|---|---|---|---|---|---|---|---|---|
| Examples | ![]() for(int i = 5; i < 95; i += 5) {
if(i < 35) {
line( 30, i, 80, i );
} else {
line( 20, i, 90, i );
}
}![]() for(int i = 5; i < 95; i += 5) {
if(i < 35) {
line( 30, i, 80, i );
} else if (i < 65) {
line( 20, i, 90, i );
} else {
line( 0, i, 100, i );
}
} | |||||||
| Description | Extends the if() structure allowing the program to choose between two or more block of code. It specifies a block of code to execute when the expression in if() is false. | |||||||
| Syntax | if(expression) {
statements
} else {
statements
}
if(expression) {
statements
} else if(expression) {
statements
} else {
statements
} | |||||||
| Parameters |
|
so basically the 'else' statement is an extension of the if statement............. on a basic level it works the same as the if statement; the computer will read the statement and follow the instructions ie. if the the r key is pressed the code will reset. The computer will only follow the code when the variation is done...... the else statement allows for there to be variations in the code for example if an 'if' statement read something like there is a circle but whilst the code is running if the mouses right button is pressed the circle will grow else if the left button is pressed the circle will shrink



No comments:
Post a Comment