What do you mean by loop?

A loop is a sequence of instructions that are executed many times, each time a different set of data. In the Assembly language, loop is used for performing looping operation.so, the Assembly language loop works as a command which executes the statement many times.
A loop can be a pre-test or a post-test loop.

1) Post-Test Loop: In the post-test loop, the code is always executed once. in post-test If the test expression evaluates to true, the loop is repeats; if the termination expression is false the loop terminates.

2) Pre-Test Loop: In a pre-test loop, the condition is checked before the beginning of the each iteration. If the test expression evaluates to true, the statements associated with the pre-test loop construct are executed and the process is repeated till the test expression becomes false. but if the test expression evaluates is false, the statements associated with the construct are skipped and the statement next to the loop is executed.
There are three loops in java:

1) for loop: The for loop is provide a compact way to iterate over a range of values. It executes a block of statements repeat continually until the any condition returns false.

 

//code for for loop

 

class demo
{
public static void main(String[] args)
{
for(int i=1; i<5; i++)
{
system.out.println("result is "+i);
}
}
}

2) while loop: The while statement continually executes a block of statement while a particular condition is true.

class demo
{
public static void main(String[] args)
{
int num=2;
while(num<11)
{
system.out.println("result is "+ num);
count++;
}
}
}

 

3) do while loop: The do-while statement within the do block are always executed atleast once.

class demo
{
public static void main(String[] args)
{
int num = 2;
do
{
system.out.println("result is: "+ num);
num++;
}
while(num<=5);
}
}

Happy codding..