If  ____ then ____

Lets take up something different for a while

What are conditions ?

What are conditions ?

 

These are the statements that can yeild a value either 0 or 1 in other words true or false

Why do we need them

To grant the ability to the computer to take decision based of conditions.

Operators : == , > , < , >= , &&                         || ,  !  and <=.

List:

1.    >=      -       greater than and equal to

2.    <=      -       less than and equal to

3.     <       -        less than

4.     >       -       greater than

5.     ==     -       equals to 

6.     !        -       negation

7.    &&     -      and

8.    ||      -       or

if( __conditions__ )

     {

           statements;

           .

           .

      }

Don't you think its quite instinctive.

Syntax:

if( __condition__ )

{

      statements;

}

else   //optional part

{

      statements;

}

int x=1;

if(x==1)

{

x=x+3;

}

else

{

x=x+1;

}

Value of x=?

if(__condition__)

{ }

else if(__condition__)

{ }

else if(__condition__)

{ }

else

{ }

Q : Try a program to find a maximum out of three numbers using this concept

We can use more than one simultaneously :

Made with Slides.com