Saturday 21 September 2013

Conditional Statements in programming

Conditional Statements (Decision Making)
Here we are going to discuss with you the conditional statements in c and in conditional statements in PHP and conditional statements in programming.

In everyday life, we are often making decisions. We perform different tasks while taking decisions. For example, the statement ‘if the milk shop is open, bring one liter of milk while returning home from college’, involves this phenomenon. In this statement, there is an element of decision making. We bring one liter of milk if the shop is open. And if the shop is closed, we come back to home without milk.
Thus we are making a decision on the condition that the shop is open. The decision-making process is everywhere in our daily life. We see that the college gives admission to a student if he has the required percentage in his previous examination and/or in the entry test. Similarly administration of a basketball team of the college decides that the students having height more than six feet can be members of the team.
Every programming language provides a structure for decision making. ‘C’ also provides this structure. The statement used for decisions in ‘C’ language is known as the ‘if statement’. The if statement has a simple structure. That is

If(condition){
            Statement (or group of statements)
}

For example if we want to statement on the screen show welcome to Programming Dost if x=10 we will write this statement in C like this

If(x==10){
            cout<<”Welcome to My Online Mela”;
}

In PHP we will write this statement like this
If($x==10){
            Echo ”Welcome to My Online Mela”;
}


Algebraic
In PHP
In language C
Example
Meaning
Greater Than
> 
> 
> 
a>b
a is greater than b
Equal to
=
==
==
a==b
a is equal than b
Less than
< 
< 
< 
a<b
a is less than b
Greater than or equal to
> 
>=
>=
a>=b
a is greater than or equal to b
Less than or equal to
< 
<=
<=
 a<=b
a is less than or equal to b
Not equal to
!=
!=
a!=b
a is not equal to b


No comments:

Post a Comment