Tuesday, May 15, 2012

If Else Statement (Conditional): Beginning

Hello Guys!! How are you, all? Hope you all are well by the grace of Almighty ALLAH. Today we learn about the conditional Statement.

Conditional Code:

  • The if statement.
  • The if.....else statement.
  • The if.....else if.....else statement.

Conditions:

  1. Using relational or conditional operators.
  2. Using logical operators.

Relational or conditional operators:

  1. == means 'is equal to'
  2. !=  means 'is not equal to'
  3. <   means 'is less than'
  4. >   means 'is greater than'
  5. <= means 'is less than or equal to'
  6. >= means 'is greater than or equal to'

Logical Operators:

  1. &&  means 'AND'
  2. ||      means 'OR'
  3. !      means 'NOT'

Note: Result of the condition is always wither true(1) or false(0)

Example: 

1>2       Ans. 0
1<2       Ans. 1
1==2     Ans. 0
If the value of the condition is any positive or negative number except 0 or 1, it always consider that number as a true value.

The If Statement

if (condition)
{
    statement;
}

Multiple statement within If

if (condition)
{
    statement 1;
    statement 2;
    -----------;
    statement n;
}

The if else statement

if (condition)
{
    statement 1;
    statement 2;
}

else
{
    statement 1;
    statement 2;
}

The if-else if-else statement

if (condition)
{
    statement 1;
    statement 2;
}

else if (condition)
{
    statement 1;
    statement 2;
}

else
{
    statement 1;
    statement 2;
}


Thank you all..:)

0 comments:

Post a Comment