Page 166 - Cs_withBlue_J_C11_Flipbook
P. 166
08
STATEMENTS AND SCOPE
Learning Objectives
8.1 Different Types of Statements 8.2 Scope of Variables
8.3 Compound Statements 8.4 Control Statements
8.5 Mathematical Functions
A set of instructions written in the correct order in any programming language performs a specific function.
These instructions are basically a set of commands which directs the compiler to carry out the desired task. These
instructions are called “Statements”. In this chapter, we shall deal with all types of statements and their uses in Java
programming.
8.1 DIFFERENT TYPES OF STATEMENTS
There are three types of statements in Java which are as follows:
• Expression Statements
• Declaration Statements
• Control Statements
Let us discuss them one by one:
8.1.1 Expression Statements
These statements consist of an expression that calculates certain equations and produces a result. They may involve
calculations such as a+b, 4*(4%2), etc. or expressions that modify the value of a variable in a program such as a++, --b
or even int add=a+b;
8.1.2 Declaration Statements
These statements are used to declare what type of data the variables or constants will contain.
For example,
int sum; double pi; boolean flag; char ch;
int sum=0; double pi=3.142; boolean flag=true; char ch='a';
8.1.3 Control Statements
These statements are used to decide in which direction the program will execute. There are mainly four types of control
statements. They are—Sequential statements, Conditional statements, Iterative statements and Jump statements.
164164 Touchpad Computer Science-XI

