Scala If Else Statement and Expressions:
if else statements are used to test the conditions in the scala.
will go through one by one:
Only executes if the conditions is true.
Syntax:
2)if and else clause as a statements:
Executes if the conditions is true else the default value prints out on the console.
Syntax:
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:
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
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
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)Example:
{}
else
{}
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)Example:
{}
else if
{} else{}
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