Java4teachus

Tuesday, February 26, 2019

Control Structures in Java

Control Structure 


In any programming languages  to perform any logical operations of a program like whether the condition statement is true or false. So let us have to know about the control statements  or structures in java .

The purpose of control statements is to perform the operations at only once whether condition is true or false  (or) To perform the operations repeatedly until   the condition is become false.

Most of the programming languages the control structures are classified into 3 types. They are :
  1. Conditional Statements
  2. looping / interactive Statements
  3. Miscellaneous  Statements

Control Statements

The control statement is mainly used  for performing either the condition is true or false. The operation is  once depends upon on the condition evaluation. We have 3 type of conditional statements. They are :

1)  if  
2) if else
3) switch

Flowchart For Conditional Statement




Syntax For if Statement:

if (Test Condition)
{
Executable block of statement's ;
}
statement-x ;

Syntax For if else Statement:

if (Test condition)
{
Executable block of statement's; → 1
}
else
{
Executable block of statement's ; →2
}
statement-x ;

Looping statements

This statements is used for performing some operations repeatedly until condition becomes false.We have 3 types of looping statements.They are :

 1) While
 2) Do while
 3) For

All the time of dealing with loop statements the programmer must ensure 3 parts. They are :

A) Initialization part    ( where to start )
B) Condition part         ( how many types to be repeated )
C) Updation part          ( Increment / Decrement ratio)


Flowchart For Looping Statements



Syntax for while:

While (Test Condition)                   
{
Execute Block of Statement's ;
}
Statement-x


Syntax do while:

do
{
Execute
Block of statements)
} While (Test cond )
 Statement-x

Syntax for looping:

 for ( Initialization part; conditional part; operation part )
 {
 Execute Block of statements ( s );
 }
 Statements-x

No comments:

Post a Comment

Thanks for visiting my site..