Title: Simple while loop Java Example (with video) - Java Code Geeks
Open Graph Title: Simple while loop Java Example (with video) - Java Code Geeks
Description: Check Java while loop examples! The while statement continually executes a block of statements while a particular condition is true.
Open Graph Description: Check Java while loop examples! The while statement continually executes a block of statements while a particular condition is true.
Mail addresses
support@javacodegeeks.com
Opengraph URL: https://examples.javacodegeeks.com/simple-while-loop-java-example/
Generator: WordPress 6.9.4
Domain: examples.javacodegeeks.com
{"@context":"https://schema.org","@graph":[{"@type":"Article","@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#article","isPartOf":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/"},"author":{"name":"Shaik Ashish","@id":"https://examples.javacodegeeks.com/#/schema/person/68f3841405b31df14aedc91af4eeb7b3"},"headline":"Simple while loop Java Example (with video)","datePublished":"2012-11-11T19:20:02+00:00","dateModified":"2022-07-06T10:57:35+00:00","mainEntityOfPage":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/"},"wordCount":330,"commentCount":0,"publisher":{"@id":"https://examples.javacodegeeks.com/#organization"},"image":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#primaryimage"},"thumbnailUrl":"https://examples.javacodegeeks.com/wp-content/uploads/2012/12/java-logo.jpg","keywords":["java basics","while loop"],"articleSection":["while loop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https://examples.javacodegeeks.com/simple-while-loop-java-example/#respond"]}]},{"@type":"WebPage","@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/","url":"https://examples.javacodegeeks.com/simple-while-loop-java-example/","name":"Simple while loop Java Example (with video) - Java Code Geeks","isPartOf":{"@id":"https://examples.javacodegeeks.com/#website"},"primaryImageOfPage":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#primaryimage"},"image":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#primaryimage"},"thumbnailUrl":"https://examples.javacodegeeks.com/wp-content/uploads/2012/12/java-logo.jpg","datePublished":"2012-11-11T19:20:02+00:00","dateModified":"2022-07-06T10:57:35+00:00","description":"Check Java while loop examples! The while statement continually executes a block of statements while a particular condition is true.","breadcrumb":{"@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https://examples.javacodegeeks.com/simple-while-loop-java-example/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#primaryimage","url":"https://examples.javacodegeeks.com/wp-content/uploads/2012/12/java-logo.jpg","contentUrl":"https://examples.javacodegeeks.com/wp-content/uploads/2012/12/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https://examples.javacodegeeks.com/simple-while-loop-java-example/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://examples.javacodegeeks.com/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https://examples.javacodegeeks.com/category/java-development/"},{"@type":"ListItem","position":3,"name":"Java Basics","item":"https://examples.javacodegeeks.com/category/java-development/java-basics/"},{"@type":"ListItem","position":4,"name":"while loop","item":"https://examples.javacodegeeks.com/category/java-development/java-basics/while-loop/"},{"@type":"ListItem","position":5,"name":"Simple while loop Java Example (with video)"}]},{"@type":"WebSite","@id":"https://examples.javacodegeeks.com/#website","url":"https://examples.javacodegeeks.com/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https://examples.javacodegeeks.com/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://examples.javacodegeeks.com/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https://examples.javacodegeeks.com/#organization","name":"Exelixis Media P.C.","url":"https://examples.javacodegeeks.com/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https://examples.javacodegeeks.com/#/schema/logo/image/","url":"https://examples.javacodegeeks.com/wp-content/uploads/2022/06/exelixis-logo.png","contentUrl":"https://examples.javacodegeeks.com/wp-content/uploads/2022/06/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https://examples.javacodegeeks.com/#/schema/logo/image/"},"sameAs":["https://www.facebook.com/javacodegeeks","https://x.com/javacodegeeks"]},{"@type":"Person","@id":"https://examples.javacodegeeks.com/#/schema/person/68f3841405b31df14aedc91af4eeb7b3","name":"Shaik Ashish","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https://examples.javacodegeeks.com/#/schema/person/image/","url":"https://examples.javacodegeeks.com/wp-content/uploads/2019/12/ash-96x96.jpg","contentUrl":"https://examples.javacodegeeks.com/wp-content/uploads/2019/12/ash-96x96.jpg","caption":"Shaik Ashish"},"description":"He completed his Bachelors Degree in Computer Applications. He is a freelancer, writer, Microsoft Certified in Python and Java. He enjoys Writing, Teaching, Coding in Java and Python, Learning New Technologies and Music.","url":"https://examples.javacodegeeks.com/author/shaik-ashish/"}]}
{"@context":"http:\/\/schema.org","@type":"BreadcrumbList","@id":"#Breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"item":{"name":"Home","@id":"https:\/\/examples.javacodegeeks.com\/"}},{"@type":"ListItem","position":2,"item":{"name":"Java Development","@id":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"}},{"@type":"ListItem","position":3,"item":{"name":"Java Basics","@id":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/java-basics\/"}},{"@type":"ListItem","position":4,"item":{"name":"while loop","@id":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/java-basics\/while-loop\/"}}]}
{"@context":"http:\/\/schema.org","@type":"Article","dateCreated":"2012-11-11T19:20:02+02:00","datePublished":"2012-11-11T19:20:02+02:00","dateModified":"2022-07-06T13:57:35+03:00","headline":"Simple while loop Java Example (with video)","name":"Simple while loop Java Example (with video)","keywords":"java basics,while loop","url":"https:\/\/examples.javacodegeeks.com\/simple-while-loop-java-example\/","description":"1. Introduction With this example we are going to demonstrate how to use a simple while loop Java statement. The while statement continually executes a block of statements while a particular condition","copyrightYear":"2012","articleSection":"while loop","articleBody":"\n1. Introduction\n\n\n\nWith this example we are going to demonstrate how to use a simple while loop Java statement. The while statement continually executes a block of statements while a particular condition is true. In short, to use a simple while loop you should:\n\n\n\nCreate a while statement that evaluates an expression, which must return a boolean value and has a statement.If the expression evaluates to true, the while statement executes the statement in the while block.The while statement continues testing the expression and executing its block until the expression evaluates to false.\n\n\n\nYou can also check Loops in Java in the following video:\n\n\n\n For loop, while loop and do while loop in Java - Video\n\n\n\nLet\u2019s take a look at the code snippet that follows: \n\n\n\n\n\n\n\n\n\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n\n\n\npackage com.javacodegeeks.snippets.basics;\n \npublic class SimpleWhileLoopExample {\n \n public static void main(String[] args) {\n \n int i = 0;\n int max = 5;\n \n System.out.println(\"Counting to \" + max);\n \n while (i < max) {\n i++;\n System.out.println(\"i is : \" + i);\n }\n \n }\n \n}\n\n\n\n\n\n\n\n\n\n\nOutput\n\n\n\nCounting to 5\ni is : 1\ni is : 2\ni is : 3\ni is : 4\ni is : 5\n\n\n\n2. Control Flow Diagram\n\n\n\nIn this flow given below, as part of while loop execution, at first, the test expression which evaluates to boolean value is executed. If the boolean condition evaluates to True, then the statements inside the body of the loop will be executed. Once the execution of statement(s) inside the loop gets over, then the test expression is again evaluated. Only when the condition evaluates to False, then the execution of the loop terminates. \n\n\n\nFig:1 While Loop Control Flow\n\n\n\n3. While loop with assignment \n\n\n\nIn this section let us get to know a program which utilizes the while loop with assignment\n\n\n\npublic class WhileWithAssignment\n{\n\tpublic static void main(String[] args) {\n \n boolean var=true;\n while(var=getNext())\n {\n \tSystem.out.println(\"Inside while\");\n \tvar=true;\n }\n System.out.println(\"Outside while, value of var is: \"+var);\n}\n\n public static boolean getNext()\n {\n \treturn false;\n }\n}\n\n\n\n\nOutput\n\n\n\nOutside while, value of var is: false\n\n\n\n\nFirst, the variable var is initialized with true. In the parenthesis of while, getNext() method is called. It returns false and assigns false to the variable var. Finally, the statement after while loop is executed.\n\n\n\n4. More articles\n\n\n\nFor Each Loop Java 8 ExampleFor loop Java ExampleJava Switch Case Example\n\n\n\n5. Download the Source Code\n\n\n\nThis is an example of Simple While Loop in Java.\n\n\n\nDownload\nYou can download the full source code of this example here: Simple while loop Java Example\n\n\n\nLast updated on Apr. 29th, 2021\n","publisher":{"@id":"#Publisher","@type":"Organization","name":"Examples Java Code Geeks","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2013\/05\/JavaCodeGeeks-logo.png"},"sameAs":["https:\/\/feeds.feedburner.com\/examplesjavacodegeeks","https:\/\/www.facebook.com\/javacodegeeks","https:\/\/twitter.com\/javacodegeeks","https:\/\/www.linkedin.com\/groups\/3810709\/","https:\/\/www.youtube.com\/channel\/UCxoUc7Rar2q90Gu0nT2ffuQ","https:\/\/github.com\/javacodegeeks\/"]},"sourceOrganization":{"@id":"#Publisher"},"copyrightHolder":{"@id":"#Publisher"},"mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/simple-while-loop-java-example\/","breadcrumb":{"@id":"#Breadcrumb"}},"author":{"@type":"Person","name":"Shaik Ashish","url":"https:\/\/examples.javacodegeeks.com\/author\/shaik-ashish\/"},"image":{"@type":"ImageObject","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":1200,"height":150}}
| og:locale | en_US |
| og:type | article |
| og:site_name | Examples Java Code Geeks |
| article:publisher | https://www.facebook.com/javacodegeeks |
| article:published_time | 2012-11-11T19:20:02+00:00 |
| article:modified_time | 2022-07-06T10:57:35+00:00 |
| og:image | https://examples.javacodegeeks.com/wp-content/uploads/2012/12/java-logo.jpg |
| og:image:width | 150 |
| og:image:height | 150 |
| og:image:type | image/jpeg |
| author | Shaik Ashish |
| twitter:card | summary_large_image |
| twitter:creator | @javacodegeeks |
| twitter:label1 | Written by |
| twitter:data1 | Shaik Ashish |
| twitter:label2 | Est. reading time |
| twitter:data2 | 3 minutes |
| None | IE=edge |
| msapplication-TileImage | https://examples.javacodegeeks.com/wp-content/uploads/2013/05/JavaCodeGeeks-favIcon.png |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1