Tuesday, August 18, 2009

JavaFX Script Controls And Expressions

block

block is a complete expression which is set between curly braces and return type is set to the variable

def seq = ["JavaFX", "Silverlight", "Flash"];

var size = { //size is set to sizOfSeq as evaluated by the expression inside curly braces
   var sizeOfSeq = sizeof(seq);
}

println("Size is {size}.");

if

if evaluates a condition and than decide whether to execute a block of code

if(marks < 30){
   println("Sorry, you will have to take retest");
}else if(marks > 30 and marks <70){
   println("Keep it up but scope to improve");
}else{
   println("Hurray! you won a scholarship");
}

for

for is used to iterate over a sequence

def seq = ["JavaFX" , "Silverlight", "Flash"];

for(value in seq){
  print(value);
}

while

while is used to loop till a condition is meet

def num = 5;
var counter = 0;

while(counter < num){
  println(counter++);
}

break

break is used to break the loop

def num = 5;
var counter = 0;

//This will print 0,1,2 only
while(counter < num){

   if(counter ==3){
      break; //will break the loop when counter becomes 3.
   }

   println(counter++);
}

continue

continue will skip that particular iteration, when the condition is matched

def num = 5;
var counter = 0;

//This will print 0,1,2,4 and 3 is skipped
while(counter < num){
 if(counter ==3){
    counter++; //Increment the counter otherwise it will always loop here
    continue; //Skip the rest part of this iteration and go to next iteration
 }
 println(counter++);
}

More on JavaFX

No comments:

Post a Comment