Circling Statement in Java


Circling Statement in Java

Circling articulation are the announcements execute one or more proclamation more than once a few number of times. In java programming dialect there are three sorts of circles; while, for and do-while.

Why use circle ?

When you have to execute a square of code a few number of times then you have to utilize circling idea in Java dialect.

Advantage with circling explanation

  • Lessen length of Code
  • Consume less memory room.
  • Trouble on the engineer is decreasing.
  • Tedious procedure to execute the project is decreased.

Distinction amongst restrictive and circling articulation

Restrictive proclamation executes just once in the system where as circling articulations executes more than once a few number of time.

While circle

In while circle first check the condition if condition is genuine then control goes inside the circle body generally goes outside of the body. while circle will be rehashes in clock insightful bearing.

Syntax

while(condition)
{
Statement(s)
Increment / decrements (++ or –);
}

Example while loop

class  whileDemo
{
 public static void main(String args[])
 {
 int i=0;
 while(i

Output

1 2 3 4 5

for loop

for loop is a statement which allows code to be repeatedly executed. For loop contains 3 parts Initialization, Condition and Increment or Decrements

Syntax

for ( initialization; condition; increment ) { statement(s); }  

  • Instatement: This progression is execute first and this is execute just once when we are going into the circle first time. This progression is permit to announce and introduce any circle control variables.
  • Condition: This is next stride after instatement step, on the off chance that it is valid, the body of the circle is executed, in the event that it is false then the body of the circle does not execute and stream of control goes outside of the for circle.
  • Augmentation or Decrements: After culmination of Initialization and Condition steps circle body code is executed and afterward Increment or Decrements steps is execute. This announcement permits to upgrade any circle control variables.

Flow Diagram

Control flow of for loop

  • First initialize the variable
  • In second step check condition
  • In third step control goes inside loop body and execute.
  • At last increase the value of variable
  • Same process is repeat until condition not false.

Display any message exactly 5 times.

Example of for loop

class  Hello
{
public static void main(String args[])
{
int i;
for (i=0: i

Output

Hello Friends ! Hello Friends ! Hello Friends ! Hello Friends ! Hello Friends !

5>

5>


Leave a Reply