× About Us How it works Pricing Student Archive Subjects Blog Contact Us

Enrich your knowledge with our informative blogs

What is statement in Programming?

Statement in a programming means any line of code that instructs the compiler to perform a specific task. 

A computer program is a set of such statements. There can be multiple types of statements in a program code that controls the input and output of the actions that a program is designed for.   

What is the role of a statement in a program? 

It’s the computer program that tells the computer to perform or to take action. A statement can be a set of symbols, numbers or pneumonics used in a program. 

For example: 

int   x; 

This is a simple declaration statement from C language which declares an integer variable named ‘x’. 

Types of programming statements  

A program consists of various types of statements.  

While assignment and declaration statements help a variable understand its data type and assign its value, flow control statements direct the sequence of the execution of the program.  

Every programming language has its own format and syntax that is to be followed by the programmer while writing the code.  

There are essentially seven types of programming statements. Let’s have a look. 

  1. Declaration statements  
  2. Labeled statements  
  3. Expression statements  
  4. Selection statements 
  5. Iteration statements  
  6. Compound statements  
  7. Jump statements 

Now, let’s discuss them in detail.   

1). Declaration statements 

As mentioned in the above example, a declaration statement is used to introduce a variable or an identifier into the program or module. 

2). Labeled statements  

These statements usually contain a label and are used to direct the flow of execution in a program.  

Considering the C/C++ language, labels are used for redirecting the control to “switch” and “goto” statements. It can be a case label or a default label in a switch statement. 

In C/C++ it is must to use a colon(:) after a label to define it. 

For a switch statement, it is written as: 

case label_expr : statement  

This means that control of the program will reach this point if the label or the expression of the switch gets matched with that of the program. 

You need to give a default label, which will make the thing run in case nothing matches with the labels of the switch statement.  

3). Expression statements  

With perspective to C/C++, any statement which is followed by a semicolon (;) is termed as an expression.  

Example: The input/output commands such as printf and scanf statements are a typical example of expression statements.  

4). Selection statements  

These statements help to make a decision using “if” clause. 

In C/CPP there are three types of selection statements: 

1. IF Statement  

Syntax: 

if (expression) 

         statement_1; 

Here, if the expression is true then, program control executes statement_1 else leaves. 

2. IF-ELSE Statement  

Syntax: 

if (expression) 

          statement_1; 

else  

         statement_2; 

Here, if the expression is true then statement_1 gets executed else the program control shifts to statement_2. 

3. Nested IF-ELSE Statement  

Syntax: 

if (expression_1) 

          {  if(expression_2)    statement_1; } 

else  

         statement_3; 

Here, multiple if-else statements are used to decide the flow of control. 

Apart from that switch statements also come under this category where the selection is made using the case statements. 

5). Iteration statements  

Iteration statements include the ones which require running the same code again and again till a fixed number of times.  

In C/C++ there are three type of iteration statements. 

  • For loop 
  • While loop 
  • Do-while loop 

6). Compound statements  

Compound statement is a group pr block of statements combined together.  

Programs usually need brackets {,} to bind more than one statement. Thereby, forming a compound statement.  

Also, variables that are declared within the braces have a scope limited to that block only.  

7). Jump statements 

To transfer the flow of control unconditionally, some jump statements are used. 

For example: return, goto, continue, break etc.  

While using jump statements every programmer must note that when the control jumps out of a block or loop, may involve destruction that were declared in the local scope.  

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

Unveil your gateway to a lucrative career!
Unveil your gateway to a lucrative career!

Unleash the power of true logic building with Real-time instructions and live coding exposure.

Book A Demo Class

Tel Guru
Tel Guru

Register For The Demo Class

[footer-form]