top of page
Search
Writer's pictureHarshit Sharma

Statements in C++

Statements:Statement are instructions given to the computer to perform any kind of action the movement of data and making decision.

Statements are divided into these categories:

1.Sequence statement: These statements are those which are executed line by line which means execution of statement sequentially.

Statement 1;

Statement 2;

2.Selection statement :These statement are those statement whose execution depends upon a execution test if the expression evaluates to true the result is the output or the expression evaluates to false and terminate the program and if any other statement or expression is evaluated whether its true or not.

Condition or Expression-----True--------->Statement1

Statement 2

These are further of these types:

1.if statement:In this the condition if evaluated to true the statement is output else program is terminated if false.

Syntax: If(expression)

statement;

2.if else :In this the condition if evaluated to true the statement 1 is output else the next statement 2 which is output.

Syntax: If(expression)

statement 1;

else

statement 2;

3.if else if ladder:In this the if holds a expression if it evaluated to trure statement 1 and if false there is expression in else if and if it is true statement 2 and this also is false then the else block statement is printed that is statement 3

Syntax:If(expression1)

statement 1;

else if(expression 2)

statement 2;

else

statement 3;

4.Nested if :It includes if within other if statement.

5. Switch statement: This statement is used to check the statements based on the cases upon the case entered by the user and if either case evaluates true that statement is printed and if no statement true then default statement printed.

Syntax: switch(expression)

{

case 1: statement 1;

break;

case 2: statement 2;

break;

case n: statement n;

break;

default: statement;

}

3. Iteration statements:These are those statement which means repetition of a set of statement s depending on the condition until the result is evaluated to either true or false it keeps on executing.These are also even known as looping statements.

These are divided into these categories:

1.For loop:The loop is used to repeat the statements again and again and all the initialization ,expression and update expression all in one line at top.

Syntax: for(initialization; test expression; update expression )

body of loop;

2.while loop:The loop is used to repeat the statement and it is called a entry controlled loop.

Syntax: while(expression )

body of loop;

2 .do while loop:The loop is called as exit controlled loop and once this statement gets even without checking the expression

Syntax: do

{

statement;

}while(test expression);

4.Jump Statements: These are some jumping statements in C++ which are used to perform some tasks for easy processing and terminating the execution.

1. Goto statement: A goto statement is used to transfer the control of the program to another statement in the program with its label.

Syntax: goto label;

2.break statement :This statement is used to break the control of loop or cases and terminate out of program as soon as statement gets executed.

Syntax: break;

3.continue:The continue statement is used to move to the starting of the block where the statement got executed but not terminating the code unless all the expression are evaluated.

Syntax: continue;

1 view0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page