{"id":2226,"date":"2016-06-05T09:27:09","date_gmt":"2016-06-05T09:27:09","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2226"},"modified":"2021-09-20T13:53:33","modified_gmt":"2021-09-20T13:53:33","slug":"java-program-for-while-loop","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-for-while-loop\/","title":{"rendered":"Java program for while loop"},"content":{"rendered":"<h3>Program Description<\/h3>\r\n<p>Write a java program to demonstrate a simple while loop. We use a while loop in a program when we know the exit condition and not sure how many times to loop the iterations.\u00a0 The loop will be executed until the loop expression is true.<\/p>\r\n<p>There is another variation of the loop called the do-while loop. Do-while will loop at-least once before evaluating the loop condition.<\/p>\r\n<h3>Syntax<\/h3>\r\n<p><strong>while (expression)<\/strong><\/p>\r\n<p><strong>{<\/strong><\/p>\r\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \/\/statements(s)<\/strong><\/p>\r\n<p><strong>}<\/strong><\/p>\r\n<p>&nbsp;<\/p>\r\n<h3>Java Program<\/h3>\r\n<p>For example, we want to exit the loop when the count reaches 10.\u00a0 Below is a simple Java program to make use of the while loop.<\/p>\r\n<p>The while loop will be executed 10 times and the loop is exited when count reaches 11.<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/***********************************************************\r\n * WhileLoop.java\r\n * @program : Java program for while loop\r\n * @web : www.testingdocs.com\r\n * @version : 1.0\r\n ************************************************************\/ \r\n\r\npublic class WhileLoopDemo {\r\n  public static void main(String[] args)\r\n  {\r\n    int count=1;\r\n    while(count&lt;11)\r\n    {\r\n      System.out.println(\"Count is :\" + count);\r\n      count++;\r\n    }\r\n  }\r\n}\r\n<\/pre>\r\n<h3>Program Output<\/h3>\r\n<p>Count is :1<br \/>Count is :2<br \/>Count is :3<br \/>Count is :4<br \/>Count is :5<br \/>Count is :6<br \/>Count is :7<br \/>Count is :8<br \/>Count is :9<br \/>Count is :10<\/p>\r\n<p>&#8212;<\/p>\r\n<p>Java Tutorial on this website:<\/p>\r\n<p><strong><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/strong><\/p>\r\n<p>More information on Java can be found on the official website:<\/p>\r\n<p><strong><a href=\"https:\/\/www.oracle.com\/in\/java\/\" rel=\"noopener\">https:\/\/www.oracle.com\/in\/java\/<\/a><\/strong><\/p>\r\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2226\" data-postid=\"2226\" class=\"themify_builder_content themify_builder_content-2226 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Program Description Write a java program to demonstrate a simple while loop. We use a while loop in a program when we know the exit condition and not sure how many times to loop the iterations.\u00a0 The loop will be executed until the loop expression is true. There is another variation of the loop called [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2226","post","type-post","status-publish","format-standard","hentry","category-automation","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=2226"}],"version-history":[{"count":9,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2226\/revisions"}],"predecessor-version":[{"id":21044,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2226\/revisions\/21044"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}