|
|
What is the Control Statement?
|
|
Control Statement are the ways for programmer to control which pieces of the
program to be executed at certain times. The syntax of the Control statements are
very similar to the regular english, and they are very similar to the choices that
we do make in our every day life. There exists two basic types of the control statements: branching statements and loops.
|
|
A branching statement
|
|
A branching statement is one which divides the code into certain number of
branches depending upon some coditions specified. Example for branching statement
is the If statement.
|
if (x > 0)
cout<<x is positive integer;
else
cout<<x is negitive integer;
|
|
|
Depending on the condition certain series of events will be executed. Another
example for branching statement is a switch statement. Let us study switch statement
later. Here in the code given above will checks the condition if x is greater than "0"
or not. if it is greater then prints x is a positive number otherwise prints
x is a negitive number.
|
|
Nested control statements
|
|
Here in the nested control statements, statements are nested by using the keyword
If and Else
|
if (x>0)
cout<<x is positive integer;
else
if (x<0)
cout<<x is negitive integer;
else
cout<<x is Zero;
|
|
|
In the example given above there is one control statement which is inside another
control statement. This method of writing program is known as nesting.
|
|
The While Statement
|
|
In this statement while keyword is been used, It checks the conditions, if it holds good
then block of code is executed. Otherwise the next sequential line of code is been
executed.
|
while (x< 0)
cout<<x is positive integer;
end while;
x=0;
|
|
|
Here if x is greater than "0" then it prints x is positive integer otherwise it simply
assigns zero to x.
|
|
The for command.
|
|
This is the loop statement. A line of code or the block of code is been executed for
certain number of times as specified in the for statement. There are three parameters
in the for statement. First intialization, second condition and finally increement
statement.
|
for(i=0;i<5;i++)
cout<<i;
|
|
|
A for statement execute a code for specified number of times. In this instance it
executes 5 times. It executes until the condition "i<5" fails.
|
|
The switch statement
|
|
A switch statement allows the programmer to compound the group of if statements, provided
that a condition being tested is integer. A switch statement is of the form shown below:
|
switch(integer_val)
{
case val_1:
// code to execute if integer_val is val_1
break;
...
case val_n:
// code to execute if integer_val is val_n
break;
default:
// code to execute if integer_val is none of the above
}
|
|
|
Default clause is kept optional, but is a good programming practice to include it.
A default clause is been executed if none of other clauses are executed.
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords Control Statement, visual basic statement, visual basic control, source code control,
vb net control, asp net control, control statements, visual basic net control,
destination control statement, sql server statement, key control sop, javascript control statements,
control statements in java, create control, control sample, control oracle, button control,
control text, form control, use control, use statement, using control, control set,
control excel, control msdn, control display, control report, control quality,
control tutorial, control example, control programming
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
| Database Quizes |
|
|
| Operating System Quizes |
|
|
| Software Testing Quizes |
|
|
| SAP Module Quizes |
|
|
| Networking Programming Quizes |
|
|
| Microsoft Office Quizes |
|
|
| Accounting Quizes |
|
|
| Computer Basics Quizes |
|
|
|