{"id":111,"date":"2021-03-11T17:45:55","date_gmt":"2021-03-11T17:45:55","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/?page_id=111"},"modified":"2021-03-15T19:39:22","modified_gmt":"2021-03-15T19:39:22","slug":"conditional-loops","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/nat4\/conditional-loops\/","title":{"rendered":"Conditional Loops"},"content":{"rendered":"<p>Conditional loops will keep repeating until a <a href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/conditions\/\">condition<\/a> is met.<\/p>\n<p>The condition can be checked at the start of the the loop:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\nage = 0 #anything except -1\r\nwhile age != -1:\r\n    age = int(input('Enter age, -1 to finish:'))\r\n    days = round(age * 365.25)\r\n    print(f'You are over {days} days old')\r\n#\r\n<\/pre>\n<p>or at the end (this is effectively a repeat-until loop):<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\nwhile True:\r\n    age = int(input('Enter age, -1 to finish:'))\r\n    days = round(age * 365.25)\r\n    print(f'You are over {days} days old')\r\n    if age == -1:\r\n        break\r\n#\r\n<\/pre>\n<p>&nbsp;<\/p>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Conditional loops will keep repeating until a condition is met. The condition can be checked at the start of the the loop: # age = 0 #anything except -1 while age != -1: age = int(input(&#8216;Enter age, -1 to finish:&#8217;)) days = round(age * 365.25) print(f&#8217;You are over {days} days old&#8217;) # or at the end (this is effectively a repeat-until loop): # while True: age = int(input(&#8216;Enter age, -1<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/nat4\/conditional-loops\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":297,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-111","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":7,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/111\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/111\/revisions\/172"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/297"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/media?parent=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}