Saturday, 25 February 2017

Decision - making statement




var i = 25;
var j = 5;
var k = 45;
var total = 0;
var status = true;
// if statement
if i != 5
{
print(i);
}

// if...else statement
if k == 5
{
print(k);
}else{
print("This is not pass the equality challenge, Try Again!");
}

// if...else statement
if k == 5
{
print(k);
}else if k == 45{
print(k);
}else{
print("This is not pass the equality challenge, Try Again!");
}

// if...else statement
if i<k
{
if j < k
{print(k);}
}else{
print("This is not pass the equality challenge, Try Again!");
}

// ternary / conditional operator
print(status ? i : "This is false!");

// switch statement
switch(k)
{
case 4 :
print("value of k : \(k)") ;
break;

    case 45 :
print("value of k : \(k)");
break;

default :
print("There are no value.") 
break;

}

No comments:

Post a Comment