Tuesday, 26 September 2017

5)Scala programming constructs: If Else Statement and Expressions:

Scala If Else Statement and Expressions:
if else statements are used to test the conditions in the scala.

will go through one by one:
  • if clause as a statement
  • if and else clause as a statement
  • if, else if, and else clause as a statement
  • if and else clause as expression
1)if clause as a statement
Only executes if the conditions is true.

Syntax:
if(condition){ }
Example:




2)if and else clause  as a statements:
Executes if the conditions is true else the default value prints out on the console.

Syntax:
if(condition)
{}
else
{}
Example:



3)if, else if and else clause  as a statements:
Executes if the conditions is true else inside the else if ,else  the default value prints out on the console.

Syntax:
if(condition)
{}
else if
{} else{}
Example:




4)if and else clause as expression:
like ternary operator in our previous programming java.

Example:

var num_apples = if(persons>10) (persons * apples_per) else default_app










No comments:

Post a Comment

Fundamentals of Python programming

Fundamentals of Python programming: Following below are the fundamental constructs of Python programming: Python Data types Python...