{"id":2713,"date":"2022-06-19T21:38:40","date_gmt":"2022-06-20T01:38:40","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/?p=2713"},"modified":"2022-06-19T21:38:40","modified_gmt":"2022-06-20T01:38:40","slug":"loops-what-are-they-and-why-do-we-need-them","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/2022\/06\/19\/loops-what-are-they-and-why-do-we-need-them\/","title":{"rendered":"Loops-What are they and why do we need them?"},"content":{"rendered":"<p>Loops are here to help us when we need to repeat several lines of code. There are three types of loops. For loops, While loops, and a Do-While loop. We use a for loop when we want to a line of code to run a specific amount of times. For example, if I wanted to alert a line that states &#8220;Last Discussion Post&#8221; 5 times, I would do the following.\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2720\" src=\"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/06\/Screen-Shot-2022-06-19-at-6.26.35-PM.png\" alt=\"\" width=\"814\" height=\"176\" srcset=\"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/06\/Screen-Shot-2022-06-19-at-6.26.35-PM.png 814w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/06\/Screen-Shot-2022-06-19-at-6.26.35-PM-300x65.png 300w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/06\/Screen-Shot-2022-06-19-at-6.26.35-PM-768x166.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/p>\n<p>The for loop above alerts the line &#8220;Last Discussion Post&#8221; five times. We know this because i=0, which is us declaring what the value of i equals now. As long as i is less than or equal to five, which is what we did by writing &#8220;i&lt;=5&#8221;, the code will run. Every time the code runs, i increases by one. We know this because we wrote &#8220;i++&#8221;.\u00a0 So, because of everything we declared, when this program is run, it will display &#8220;Last Discussion Post&#8221; five times.\u00a0<\/p>\n<p>When we don&#8217;t know the specific number of times to run a loop, we use a While loop. This loop will run a line of code until the statement within the loop is false.\u00a0\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loops are here to help us when we need to repeat several lines of code. There are three types of loops. For loops, While loops, and a Do-While loop. We use a for loop when we want to a line of code to run a specific amount of times. For example, if I wanted to [&hellip;]<\/p>\n","protected":false},"author":28303,"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-2713","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\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/users\/28303"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/comments?post=2713"}],"version-history":[{"count":1,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2713\/revisions"}],"predecessor-version":[{"id":2723,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2713\/revisions\/2723"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/media?parent=2713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/categories?post=2713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/tags?post=2713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}