123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Technology,-Gadget-and-Science >> View Article

Iterative Or Loop Statements In Java

Profile Picture
By Author: jatin
Total Articles: 102
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Loop is a programming construct that allows you to execute a block of code repeatedly based on a condition. Loops in Java can be categorized based on when the loop condition is checked relative to the execution of the loop body.
These categories are commonly referred to as entry-controlled loops and exit-controlled loops.
These categories are entry-controlled and exit-controlled loops
Entry-Controlled Loop (Pre-Test Loop):
In entry-controlled loops, the loop condition is checked before the execution of the loop body. If the condition evaluates to false initially, the loop body will not be executed at all. Example of Entry-Controlled Loops:
while loop:
The java program while loop is used when you want to execute a block of code as long as a condition is true. Given condition is tested before executing the loop body.
Syntax:
while (condition) {
// code to be executed
}
condition: It is the expression evaluated before each iteration. If it evaluates to true, the loop continues; otherwise, it terminates.
// Entry-controlled while loop
int i = 0;
while ...
... (i < 5) {
System.out.println("Count is: " + i);
i++;
}
for loop:
The java for loop is used when you know exactly how many times you want to execute a block of code.
Syntax:
for (initialization; condition; update) {
// code to be executed
}
Initialization: It initializes the loop control variable.
Condition: Expression evaluated before each iteration. If it evaluates to true then the loop continues otherwise it terminates.
Update: It updates the loop control variable after each iteration.
// Entry-controlled for loop
for (int i = 0; i < 5; i++) {
System.out.println("Count is: " + i);
}
Exit-Controlled Loop (Post-Test Loop):
In exit-controlled loops, the loop condition is checked after the execution of the loop body. This means that the loop body is executed at least once before the condition is evaluated.
do-while loop
The do-while loop is similar to the while loop, but the condition is evaluated after executing the loop body. Therefore, the loop body is executed at least once.
Syntax:
do {
// code to be executed
} while (condition);
// Exit-controlled do-while loop
int i = 0;
do {
System.out.println("Count is: " + i);
i++;
} while (i < 5);
Use Case 1:
Generating table of N.
Input: N=9
Output:
9 X 1 : 9
9 X 2 : 18
9 X 3 : 27
9 X 4 : 36
9 X 5 : 45
9 X 6 : 54
9 X 7 : 63
9 X 8 : 72
9 X 9 : 81
9 X 10 : 90
Please visit our website to know more:-https://cyberinfomines.com/blog-details/iterative-or-loop-statements-in-java

Total Views: 104Word Count: 368See All articles From Author

Add Comment

Technology, Gadget and Science Articles

1. Best Paint Testing Lab In India For Industrial & Commercial Paint Analysis
Author: KINJAL

2. Best Laser Diode Machine For Skin Hair Removal Offered By Reveal Lasers
Author: reveallasers

3. Versitron M7275s-2a 10/100 Fiber Media Converter For Enterprise, Defense & Industrial Networks
Author: Versitron

4. Build Real-time Apis For Web Scraping Data Pipelines
Author: REAL DATA API

5. How To Scrape Complete Product Catalogs From E-commerce Websites For Multi-platform Product Tracking?
Author: Retail Scrape

6. Scrape Data From Quick Commerce Apps Instamart, Blinkit, & Zepto
Author: Retail Scrape

7. Best Ring Products Analytics On Amazon Saudi Arabia
Author: Actowiz Metrics

8. Schedule And Automate Data Extraction Jobs
Author: REAL DATA API

9. Automating The Employee Lifecycle With Smart Hcm Workflows
Author: Focus Softnet

10. Best Techniques For Dealing With Missing Values In Scraped Data
Author: REAL DATA API

11. Automated Retail Price Monitoring Using Web Scraping Apis
Author: Web Data Crawler

12. Why Awardocado Is The Smart Choice For Modern Award Management Software
Author: Awardocado

13. How Retailers Use Data Scraping To Win Price Wars
Author: REAL DATA API

14. Pricing Intelligence Via Airbnb Listing Data Scraping Data
Author: DataZivot

15. Building Interactive Dashboards For Scraped Data Analytics
Author: Web Data Crawler

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: