Entry Controlled Loop in Java
Below is the implementation of Entry Controlled Loop in Java:
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
public static void main(String[] args)
{
int i = 0;
// Entry controlled loop using while loop
System.out.println(
"Entry controlled loop using while loop:");
while (i < 5) {
System.out.print(i + " ");
i++;
}
System.out.println();
// Reset i for the next loop
i = 0;
// Entry controlled loop using for loop
System.out.println(
"Entry controlled loop using for loop:");
for (i = 0; i < 5; i++) {
System.out.print(i + " ");
}
System.out.println();
}
}
Output
Entry controlled loop using while loop: 0 1 2 3 4 Entry controlled loop using for loop: 0 1 2 3 4
Entry Controlled Loops in Programming
Entry controlled loops in programming languages allow repetitive execution of a block of code based on a condition that is checked before entering the loop. In this article, we will learn about entry controlled loops, their types, syntax, and usage across various popular programming languages.