• Post Reply Bookmark Topic Watch Topic
  • New Topic

Objective 4.1  RSS feed

Aleks V. Pascoal
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
here are my thoughts about this topic. Please post comments.

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;

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
case value2:
default: //just in case variable is diferent of all values
?: ternary operador, it's almost a resume of if-else
variable = expression ? return1: return2;
//if expression true returns return1, else returns return2.

Logical operators: "==", "!=", "&&", "||".

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 (condition){ //while contidion is true continues
do-while: always executed at least once
} 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 ]
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For assignment part, don't miss the difference between i++ and ++i.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!