Computer Science, asked by sirshendumaity2006, 9 months ago

what are the different types of Loops(looping statement im java) write their name with an example (syntax) of each​

Answers

Answered by giriaishik123
1

Answer:

Loops in Java

Looping in programming languages is a feature which facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true.

Java provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition checking time.

while loop: A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

Syntax :

while (boolean condition)

{

  loop statements...

}

Flowchart:

while loop

While loop starts with the checking of condition. If it evaluated to true, then the loop body statements are executed otherwise first statement following the loop is executed. For this reason it is also called Entry control loop

Once the condition is evaluated to true, the statements in the loop body are executed. Normally the statements contain an update value for the variable being processed for the next iteration.

When the condition becomes false, the loop terminates which marks the end of its life cycle.

filter_none

edit

play_arrow

brightness_4

// Java program to illustrate while loop  

class whileLoopDemo  

{  

   public static void main(String args[])  

   {  

       int x = 1;  

 

       // Exit when x becomes greater than 4  

       while (x <= 4)  

       {  

           System.out.println("Value of x:" + x);  

 

           // Increment the value of x for  

           // next iteration  

           x++;  

       }  

   }  

}  

Output:

Value of x:1

Value of x:2

Value of x:3

Value of x:4

for loop: for loop provides a concise way of writing the loop structure. Unlike a while loop, a for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.

Syntax:

Answered by ramasamhithaz
1

Explanation:

please mark me as brina list.

Attachments:
Similar questions