{"id":4046,"date":"2023-03-02T18:39:21","date_gmt":"2023-03-02T23:39:21","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=4046"},"modified":"2023-03-02T18:40:18","modified_gmt":"2023-03-02T23:40:18","slug":"6b-loops-2","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/03\/02\/6b-loops-2\/","title":{"rendered":"6b: Loops"},"content":{"rendered":"<p><span style=\"font-weight: 400\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-4052 alignleft\" src=\"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/03\/loops-300x150.png\" alt=\"\" width=\"300\" height=\"150\" srcset=\"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/03\/loops-300x150.png 300w, https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/03\/loops-768x384.png 768w, https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/03\/loops.png 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><span style=\"font-size: 10pt\">Loops are handy when you want to run the same code repeatedly with different values in each execution. There are 3 types of loops in JS:<\/span><\/span><\/p>\n<p><span style=\"font-size: 10pt\"><i><span style=\"font-weight: 400\">for () <\/span><\/i><span style=\"font-weight: 400\">loops \u2192 these loops contain 3 statements: the first is the initial expression, executed before the loop begins; the second is the condition that runs the loop; the third is the increment with each execution of the loop. If the second statement in a loop returns true, then the loop will begin again with the incremented value. If it runs false, the loop will end. A loop can also be ended using <\/span><i><span style=\"font-weight: 400\">break<\/span><\/i><span style=\"font-weight: 400\">, otherwise the loop will run forever if it can.<\/span><\/span><\/p>\n<p><span style=\"font-size: 10pt\"><i><span style=\"font-weight: 400\">while () <\/span><\/i><span style=\"font-weight: 400\">loops \u2192 these loops are used to repeat a block of code over and over until a certain condition (enclosed in the parentheses) is met. These are useful when you don\u2019t know the exact amount of times you want the code to be repeated. The result of this expression will always be a Boolean value.<\/span><\/span><\/p>\n<p><span style=\"font-size: 10pt\"><i><span style=\"font-weight: 400\">do\u2026while () <\/span><\/i><\/span><span style=\"font-weight: 400\"><span style=\"font-size: 10pt\">loops \u2192 this is a variation of the previous loop, except in this instance, the code is executed once before testing the condition. The loop will continue repeating as long as the condition is true<\/span>.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loops are handy when you want to run the same code repeatedly with different values in each execution. There are 3 types of loops in JS: for () loops \u2192 these loops contain 3 statements: the first is the initial expression, executed before the loop begins; the second is the condition that runs the loop; [&hellip;]<\/p>\n","protected":false},"author":29253,"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-4046","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\/4046","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\/29253"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=4046"}],"version-history":[{"count":2,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4046\/revisions"}],"predecessor-version":[{"id":4058,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4046\/revisions\/4058"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=4046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=4046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=4046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}