...

Cloud Computing - SCALA

Back to Course

Lesson Description


Lession - #680 SCALA IF ELSE


SCALA if else

This part takes you through the condition development statement in Scala programming. Following is the general type of a common dynamic IF...ELSE structure viewed as in the vast majority of the programming language.

if Statement

'if' statement comprises of a Boolean statement followed by 1/more statement.
syntax
The language structure of an 'if' statement is as per the following.



if(Boolean_statement>
{ // statements will execute assuming the Boolean statement is valid }

if the Boolean statement evaluate to valid/true, the block of code inside the 'if' statement will be executed. In the event that not, the primary set of code after the finish of the 'if' statement (after the end wavy support>
will be executed.

Attempt the following model program to figure out condition statement (if statement>
in Scala Programming Language.


Model
object Demo {
   def main(args: Array[String]>
{ var x = 10; if( x < 20 >
{ println("This is if statement">
; } } }

Save the above program in Demo.scala. The following orders are utilized to compile and execute this program.

Command
\>scalac Demo.scala
\>scala Demo


Output
This is if statement

if else Statement
An 'if' statement can be followed by a optional else statement, which executes when the Boolean statement is false.
syntax
The syntax of an if...else is −

if(Boolean_statement>
{ //Executes when the Boolean statement is valid } else{ //Executes when the Boolean statement is misleading }

Attempt the following model program to grasp conditional statement (if-else statement>
in Scala Programming Language.


Model

object Demo {
   def main(args: Array[String]>
{ var x = 30; if( x < 20 >
{ println("This is if statement">
; } else { println("This is else statement">
; } } }

Save the above program in Demo.scala. The following orders are utilized to compile and execute this program.

Command
\>scalac Demo.scala
\>scala Demo


Output
This is else statement