{"id":2306,"date":"2017-06-14T09:04:12","date_gmt":"2017-06-14T09:04:12","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2306"},"modified":"2024-09-04T06:46:23","modified_gmt":"2024-09-04T06:46:23","slug":"loop-structures-overview","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/loop-structures-overview\/","title":{"rendered":"Loop Structures"},"content":{"rendered":"<h1>Loop Structures<\/h1>\n<p>Loop structures are used to perform repetitive tasks in automation code. Loop structures are a block of statements that are executed repeatedly based on loop condition(s).<\/p>\n<h3>Loop Structures<\/h3>\n<p>There are basic looping structures that we can use them in java code or automation code:<\/p>\n<ul>\n<li><strong>for loop<\/strong><\/li>\n<li><strong>while loop<\/strong><\/li>\n<li><strong>do-while loop<\/strong><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2401\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Loop-Structures-Java-.png\" alt=\"Loop Structures\" width=\"1129\" height=\"786\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Loop-Structures-Java-.png 1129w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Loop-Structures-Java--300x209.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Loop-Structures-Java--1024x713.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Loop-Structures-Java--768x535.png 768w\" sizes=\"auto, (max-width: 1129px) 100vw, 1129px\" \/><\/p>\n<h3><\/h3>\n<h3>For Loop<\/h3>\n<p>For loop is executed for a fixed number of iteration. We can use this loop if we know the number of iterations beforehand. Sample Java program with a for loop:<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/questions\/java-program-using-for-loop\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.testingdocs.com\/questions\/java-program-using-for-loop\/<\/a><\/p>\n<h3>While Loop<\/h3>\n<p>While loop is entry controlled loop. The condition is executed first. If the condition is true then the body of the while loop is executed. The block of statements is executed until the loop condition becomes false.<\/p>\n<p>Sample java program to demo the while loop can be found at:<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/questions\/java-program-for-while-loop\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.testingdocs.com\/questions\/java-program-for-while-loop\/<\/a><\/p>\n<h3>Do While Loop<\/h3>\n<p>Do While loop is exit controlled loop. The condition is executed in the last. The loop is executed once and the condition is checked. If the condition is true then the body of the do-while loop is executed again. The block of statements is executed until the loop condition becomes false.<\/p>\n<p>Do while loop demo :<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/questions\/java-program-for-do-while-loop\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.testingdocs.com\/questions\/java-program-for-do-while-loop\/<\/a><\/p>\n<h3>Common Error<\/h3>\n<p>The common mistake automation testers do while working with loops is to fall into infinite loops. An infinite loop is a loop that may execute an infinite number of times.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loop Structures Loop structures are used to perform repetitive tasks in automation code. Loop structures are a block of statements that are executed repeatedly based on loop condition(s). Loop Structures There are basic looping structures that we can use them in java code or automation code: for loop while loop do-while loop &nbsp; &nbsp; For [&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-2306","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\/2306","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=2306"}],"version-history":[{"count":6,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2306\/revisions"}],"predecessor-version":[{"id":23985,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2306\/revisions\/23985"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}