{"id":1968,"date":"2016-06-02T07:35:00","date_gmt":"2016-06-02T07:35:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=1968"},"modified":"2021-03-20T16:20:23","modified_gmt":"2021-03-20T16:20:23","slug":"java-program-using-for-loop","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-using-for-loop\/","title":{"rendered":"Java program using for loop"},"content":{"rendered":"<h3>Program Description<\/h3>\r\n<p>In this post, we will write a simple java program using for loop. for loop is used for iteration to do repetitive tasks in programs or applications. We may use for loop if we know the number of iteration beforehand. The syntax for the loop is shown below:<\/p>\r\n<h3>Syntax<\/h3>\r\n<p><strong>for(initialization ; condition ; increment\/decrement)<\/strong><\/p>\r\n<p><strong>{<\/strong><\/p>\r\n<p><strong>\u00a0 \u00a0 statement(s) \/\/block of statements<\/strong><\/p>\r\n<p><strong>}<\/strong><\/p>\r\n<h3>\u00a0<\/h3>\r\n<h3>Flow Diagram<\/h3>\r\n<p>&nbsp;<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2214\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Raptor.png\" alt=\"\" width=\"1031\" height=\"969\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Raptor.png 1031w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Raptor-300x282.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Raptor-1024x962.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Raptor-768x722.png 768w\" sizes=\"auto, (max-width: 1031px) 100vw, 1031px\" \/><\/p>\r\n<h3>\u00a0<\/h3>\r\n<p>The flowchart tool used is Raptor. For more information about the flowchart tool:<\/p>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/raptor-a-flowchart-tool\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.testingdocs.com\/raptor-a-flowchart-tool\/<\/a><\/p>\r\n<h3>\u00a0<\/h3>\r\n<h3>Java Program<\/h3>\r\n<p>&nbsp;<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class ForLoopDemo {\r\n  public static void main(String args[])\r\n  {\r\n    int i;\r\n    for(i = 1; i &lt;= 10 ; i++)\r\n    {\r\n      System.out.println(\"The value of i is:\"+i);\r\n    }\r\n  }\r\n}\r\n<\/pre>\r\n<p>&nbsp;<\/p>\r\n<h3>Program Output<\/h3>\r\n<p>The value of i is:1<br \/>The value of i is:2<br \/>The value of i is:3<br \/>The value of i is:4<br \/>The value of i is:5<br \/>The value of i is:6<br \/>The value of i is:7<br \/>The value of i is:8<br \/>The value of i is:9<br \/>The value of i is:10<\/p>\r\n<h3>\u00a0<\/h3>\r\n<h3>Screenshot<\/h3>\r\n<p>&nbsp;<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2213\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo.png\" alt=\"For loop Demo\" width=\"1669\" height=\"1029\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo.png 1669w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo-300x185.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo-1024x631.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo-768x474.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/For-Loop-Demo-1536x947.png 1536w\" sizes=\"auto, (max-width: 1669px) 100vw, 1669px\" \/><\/p>\r\n<h3>Loop using multiple variables<\/h3>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class ForLoopDemo { \r\n  public static void main(String args[]) {\r\n  int i,j; \r\n  for(i = 1, j = 1; i &lt;= 10 &amp;&amp; j &lt;= 10; i++, j--) {\r\n     System.out.println(\"The value of i is:\"+i); \r\n     System.out.println(\"The value of j is:\"+j); \r\n   } \r\n }\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<h3>\u00a0<\/h3>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-1968\" data-postid=\"1968\" class=\"themify_builder_content themify_builder_content-1968 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Program Description In this post, we will write a simple java program using for loop. for loop is used for iteration to do repetitive tasks in programs or applications. We may use for loop if we know the number of iteration beforehand. The syntax for the loop is shown below: Syntax for(initialization ; condition ; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-1968","post","type-post","status-publish","format-standard","hentry","category-java-programs","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\/1968","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=1968"}],"version-history":[{"count":5,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1968\/revisions"}],"predecessor-version":[{"id":19649,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1968\/revisions\/19649"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=1968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=1968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=1968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}