{"id":3378,"date":"2023-02-27T20:18:26","date_gmt":"2023-02-28T01:18:26","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=3378"},"modified":"2023-02-27T20:18:36","modified_gmt":"2023-02-28T01:18:36","slug":"loops-in-javascript","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/02\/27\/loops-in-javascript\/","title":{"rendered":"Loops in JavaScript (6b)"},"content":{"rendered":"<p>We use loops when we want code to run more than one time. For loops run for a certain number of times specified at the beginning. While loops run for as long as a condition is met (not a specific number). For example, \u201cfor\u201d loops are great for running through a list of a certain number of objects, while \u201cwhile\u201d loops are great for performing a task while a certain condition is true. When we create a for loop, it must have three parts: the keyword that starts the loop, the condition being tested, and the end keyword that terminates the loop. An example of the syntax for a \u201cfor\u201d loop would be:<\/p>\n<p>for (let days = 1; days &lt; 8; days++){<\/p>\n<p>console.log(\u201cToday is the \u201c + days + \u201c day\u201d);<\/p>\n<p>}<\/p>\n<p>We are starting at days = 1 and printing a statement for each day. After the statement is printed, the number of days is incremented and the loop starts over. When we reach days = 8, the for loop stops and the condition is not executed since it only executes when days is less than 8. In total, the loop will run 7 times. We separate the variable \u2018days\u2019 with a \u201c+\u201d sign since we want it to print the value of the variable, not the word \u201cdays\u201d. Anything printed between quotation marks will be printed as a statement and not a variable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use loops when we want code to run more than one time. For loops run for a certain number of times specified at the beginning. While loops run for as long as a condition is met (not a specific number). For example, \u201cfor\u201d loops are great for running through a list of a certain [&hellip;]<\/p>\n","protected":false},"author":29444,"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-3378","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\/3378","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\/29444"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=3378"}],"version-history":[{"count":2,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3378\/revisions"}],"predecessor-version":[{"id":3380,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3378\/revisions\/3380"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=3378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=3378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=3378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}