Control Statements: Introduction, Objectives and Statements, Compound Statement and Null Statement

Get top class preparation for UGC right from your home: Get complete video lectures from top expert with unlimited validity: cover entire syllabus, expected topics, in full detail- anytime and anywhere & ask your doubts to top experts.

Image of control Statements

Image of Control Statements

Loading Image

Introduction

  • The normal flow of execution in a high-level language is sequential, i.e., each statement is executed in the order of its appearance in the program.

  • Control statements enable us to specify the flow of program control, i.e., the order in which the instructions in a program must be executed.

  • They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.

  • The statements which specify the order of execution of statements are called control flow statements.

  • There are many control flow statements provided in C++ that will be discussed in this lesson.

Objectives

Image of Control Statements objectives

Image of Control Statements Objectives

Loading Image

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.