{"id":4181,"date":"2023-03-02T20:37:01","date_gmt":"2023-03-03T01:37:01","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=4181"},"modified":"2023-03-02T20:37:01","modified_gmt":"2023-03-03T01:37:01","slug":"loops-and-why-use-them","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/03\/02\/loops-and-why-use-them\/","title":{"rendered":"Loops and Why Use Them"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Loops are used when you want to run your code multiple times. There are different types of loops you can use, including for, while, and do-while. Each of these loops is utilized for different purposes. For the for loop function, you would want to use it when you run the same code over again but with a different value. While loops are good when you want to perform a task over again when there is a condition that needs to be met. Do-while loops are good to use when you know you need to perform the loop at least once but aren\u2019t entirely sure how many times that loop will need to be performed. There are three parts of a loop, the keyword that starts the loop, the condition, and the keyword that ends the loop. Each loop looks a little different as well.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">The for loop looks a bit like this:<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let num = 0<\/span><\/p>\n<p><span style=\"font-weight: 400\">For ( let number =1, number &lt;5; number++)<\/span><\/p>\n<p><span style=\"font-weight: 400\">We worked on this in our last coding assignment as well.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">The while loop looks a bit like:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let num=0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">While (num &gt; 3){<\/span><\/p>\n<p><span style=\"font-weight: 400\">alert ();<\/span><\/p>\n<p><span style=\"font-weight: 400\">Count++<\/span><\/p>\n<p><span style=\"font-weight: 400\">}<\/span><\/p>\n<p><span style=\"font-weight: 400\">And the do-while loop will look a bit like:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let count = 0;<\/span><\/p>\n<p><span style=\"font-weight: 400\">Do{<\/span><\/p>\n<p><span style=\"font-weight: 400\">alert();<\/span><\/p>\n<p><span style=\"font-weight: 400\">Count++;<\/span><\/p>\n<p><span style=\"font-weight: 400\">} while (count&lt;7);<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loops are used when you want to run your code multiple times. There are different types of loops you can use, including for, while, and do-while. Each of these loops is utilized for different purposes. For the for loop function, you would want to use it when you run the same code over again but [&hellip;]<\/p>\n","protected":false},"author":29245,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[663943],"tags":[],"class_list":{"0":"post-4181","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-instructor","7":"entry"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/users\/29245"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=4181"}],"version-history":[{"count":2,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4181\/revisions"}],"predecessor-version":[{"id":4185,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4181\/revisions\/4185"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=4181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=4181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=4181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}