Thursday, 5 May 2011

Project 3---------------------------- coding exhibition

The coding term I have chosen is if/ else statements
To begin I have found the definition for the 'if' statement on processing....................
Name

if

Examples
example pic
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
expression any valid expression that evaluates to true or false
statements one or more statements to be executed
................so basically and if statement is used to tell the computer to execute a different code for example and if statement might say something like when the mouse is right clicked the ellipse that was originally black may turn pink and then when the right mouse is not being clicked the ellipse stays black...................
I next found the definition for 'else' statement on processing............
Name

else

Examples
example pic
for(int i = 5; i < 95; i += 5) {
  if(i < 35) {
    line( 30, i, 80, i );
  } else {
    line( 20, i, 90, i );
  }
}
example pic
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
expression any valid expression that evaluates to true or false
statements one or more statements to be executed

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