Control Statement in C++.

  • Programs consist of parts or instruction blocks that sit idle until required. The software switches to the appropriate section for accomplishing a task if necessary. 
  • When one section of code is occupied, the remaining sections remain inactive. Control statements are how programmers indicate at specific times which pieces of code to use.
  • Control statements are elements which control the flow of program execution in the source code. These include the use of{ and} brackets, the use of loops for, while and do while and the use of if and switch to make decisions. 
  • There's goto in there too. There are two kinds of statements of control: conditional, and unconditional.
www.mskuthar.blogspot.com
Control Statement in C++


Statements

  • Statements are the instructions given to the computer to perform any kind of action. Action may be in the form of data movement, decision making etc. 
  • Statements form the smallest executable unit within a C++ program. Statements are always terminated by semicolon.


Compound Statement

  • A compound statement is a grouping of statements in which each individual statement ends with a semi-colon. The group of statements is called block. 
  • Compound statements are enclosed between the pair of braces ({}.). The opening brace ({) signifies the beginning and closing brace (}) signifies the end of the block.


Null Statement

  • Writing only a semicolon indicates a null statement. Thus ';' is a null or empty statement. 
  • This is quite useful when the syntax of the language needs to specify a statement but the logic of the program does not need any statement. 
  • This statement is generally used in for and while looping statements.


Conditional Statements

  • Sometimes the program needs to be executed depending upon a particular condition. C++ provides the following statements for implementing the selection control structure.

  1. if statement.
  2. if else statement.
  3. nested if statement.
  4. switch statement.

Post a Comment

Previous Post Next Post