Statement
What is a statement?
A statement is a command or instruction which is given to the computer to take a specific action on what to display on the screen or which input has to collect. A program is made up of a series of statements.Example:
c=a+b
//This is not a statement.//This is an expression.
But when any expression is terminated by a semicolon(;) it is called a statement.
Example:
c=a+b;
//Now this is a statement.A program is made up of a set of instructions & statements.
There are various types of statements but on its type of nature, we have classified it in 4 types.
1.Expression statements
2.Selection statements
3.Loop statements
4.Jump statements
1. Expression statements: most of the programs followed in C are the expression statement. An expression statement is simply an expression terminated by a semicolon (;). It is the combination of operators and operands.
You will learn in detail about operators in chapter operators. In Simple language operators are +, -, ++, --, =, *, /, % etc. Operands are expressions or values on which an operator operates or works. For example, a+b where + is operator while a and b are the operands.
Examples:
int=1;
//it is also called as Declaration statement
c=a+b;
//It is also called an assignment statement because an assignment operator is used here.
float b=15;
// This is initial declaration and initialization statement
c--;
//decremement statement
c++;
// increment stateement
2. Selection statement: It is required because if we write several statements in the program. By default, all the statements are executed in sequential order. sometimes we have to change the execution order of the statement. For that purpose control flow statements are created.
i.e to controls the flow of execution of the statements for this purpose selection statements are created.
Selection statements are: if-else statements, else-if statements, switch statements, conditional operators.
Note: [By default execution of your program is done in sequential order]
3. Loop statements: In all the cases statements are executed only once but in some cases same statements with or without change it should be executed the number of times for that purpose we have to use a loop statement.
i.e for the repetition of the same action loop statement are used.
Loop control statements are: while statement, for statement, do-while statement.
4. Jump Statements: Jump statements make the control jump to another section of the program unconditionally when encountered. It is usually used to terminate the loop or switch-case instantly. It is also used to escape the execution of a section of the program.
Jump Statements are: break statement, continue statement, goto statement, return statement.
Comments
Post a Comment