WHILE LOOPS
This content covers the syntax and usage of while loops, including examples of implementing while conditions and outputting results using Java language. It also delves into the do/while loop syntax, offering insights into its structure and functionality. Additionally, the material touches on concepts like handling user input for sum calculation, utilizing the break and continue statements within loops, and demonstrating practical coding scenarios.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
WHILE LOOPS v101
While Loop Syntax while (condition) { // code block to be executed }
While Loop Syntax int i = 0; while (i < 5) { System.out.println(i); i++; }
The Do/While Loop Syntax do { // code block to be executed } while (condition);
The Do/While Loop Syntax int i = 0; do { System.out.println(i); i++; } while (i < 5);
import java.util.Scanner; break; statement class UserInputSum { public static void main(String[] args) { double number, sum = 0.0; // create an object of Scanner Scanner input = new Scanner(System.in); while (true) { while (true) { System.out.print System.out.print("Enter a number: "); ("Enter a number: "); // takes double input from user // takes double input from user number = number = input.nextDouble input.nextDouble(); (); // if number is negative the loop terminates // if number is negative the loop terminates if (number < 0.0) { if (number < 0.0) { break; break; } } sum += number; sum += number; } } System.out.println("Sum = " + sum); }
continue; statement int i = 0; while ( while (i i < 10) { { if (i == 4) { i++; continue; } System.out.println(i); i++; } } < 10)