What is Conditional Statements ?

Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.

Type of conditional Statement

if statement – use this statement if you want to execute a set of code when a condition is true.

Syntax if (condition)

{

code to be executed if condition is true

}

if…else statement – use this statement if you want to select one of two sets of lines to execute.

Syntax if (condition)

{

code to be executed if condition is true

}

else

{

code to be executed if condition is false

}

switch statement – use this statement if you want to select one of many sets of lines to execute.

Syntax switch (expression)

{

case label1:

  code to be executed if expression = label1

  break    

case label2:

  code to be executed if expression = label2

  break

default:

  code to be executed

  if expression is different 

  from both label1 and label2

}

Konw more athttp://www.cev.washington.edu

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s