• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Objective 4.1

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For assignment part, don't miss the difference between i++ and ++i.

Nick
 
Our first order of business must be this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic