Hey guys,
here are my thoughts about this topic. Please post comments.
Assignment Atributte a value to a variable. It may be a literal, a primitive or a reference to an object. Operator: "=".
Ex: int i = 10;
name = new
String("Aleks");
long l = i;
i++; // same as i = i + 1;
i+=2; // same as i = i +2;
Conditional Check the value of an expression and made a decision about witch peace of code execute
if-else: check logical expressions true/false
if (expression) { doThis} //if expression true doThis
else if (expression2) {doThat} //if expression2 true doThat
else { doThose } //otherwise doThose
switch: compare variable with values to make a decision
switch(variable){ // byte, short, int, char or Enum.
case value1: //Must be a constante value
doThis;
break;
case value2:
doThat;
break;
default: //just in case variable is diferent of all values
doDefault;
break;
}
?: ternary operador, it's almost a resume of if-else
variable = expression ? return1: return2;
//if expression true returns return1, else returns return2.
Logical operators: "==", "!=", "&&", "||".
Iteration Executes repeateddly the same code while some conditions are mantained.
Obs: break exits any loop and continue jumps to the next step of the loop.
while:
while (condition){ //while contidion is true continues
...code...
}
do-while: always executed at least once
do{
} while(condition)
for: loop determined.
//declaration/inicialization = executed once before the loop
//condition = tested on each iteration, repeated while it's true
//increment = repeated after each loop
for (declaration/inicialization; condition ; increment ){
}
for-each: enhaced loop, used with arrays or Collections
//declaration - variable with the same type of elements
//colection - Collection or array
//On each iteration take the next elementof the collection e assign to
//the variable.
for (declaration : colection){ ...code... }
[ June 29, 2005: Message edited by: Aleks V. Pascoal ]