Docsity

Loops in Java Programming, Slides of Java Programming

Partial preview of the text

Download Loops in Java Programming and more Slides Java Programming in PDF only on Docsity!

Java Fundamentals

Course

Module 6

Repeating Tasks in

Java

Introduction

โ— (^) Java provides control flow statements to execute code repeatedly โ— (^) Looping statements allow repeating tasks: โ— (^) while loop โ— (^) do-while loop โ— (^) for loop

Examples:

while (i < 10) { System.out.println(i); i++; }

do-while Loop

โ— (^) Similar to while loop, but condition checked after first iteration โ— (^) Code block executes at least once โ— (^) Syntax: โ— (^) do { // code to execute โ— (^) } โ— (^) while (condition);

Examples

โ— (^) for (int i=0; i<10; i++) { System.out.println(i); โ— (^) }

Conclusion

โ— (^) Loops allow repeating execution of code blocks โ— (^) while, do-while, for, enhanced for provide repeating control flow