{"id":273,"date":"2023-06-13T20:41:51","date_gmt":"2023-06-13T20:41:51","guid":{"rendered":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?page_id=273"},"modified":"2023-06-13T20:46:41","modified_gmt":"2023-06-13T20:46:41","slug":"indefinite-iteration","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/","title":{"rendered":"Indefinite Iteration"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Indefinite Iteration<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Indefinite Iteration<\/h3>\n<p>Indefinite iteration, also known as an indefinite loop, is used when you want to repeat a block of code until a certain condition is met. It involves iterating until a specific condition evaluates to true or false.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-274\" src=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart.png\" alt=\"\" width=\"715\" height=\"496\" srcset=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart.png 820w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart-300x208.png 300w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart-768x533.png 768w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/p>\n\n<\/div><h2 class=\"tabtitle\">While Loop<\/h2>\n<div class=\"tabcontent\">\n\n<h3>While Loop<\/h3>\n<p>In Python Indefinite iteration is commonly implemented using &#8220;while&#8221; loops.<\/p>\n<p>Here&#8217;s an example of indefinite iteration using a while loop in Python:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">while<\/span> i <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(i)\r\n    i <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Output:<\/p>\n<pre>0\r\n1 \r\n2 \r\n3 \r\n4<\/pre>\n<p>In this example, the while loop continues to execute as long as the condition <code>i &lt; 5<\/code> is true. The value of <code>i<\/code> is incremented in each iteration until it reaches 5.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Break<\/h2>\n<div class=\"tabcontent\">\n\n<h3>While loop with break<br \/>\n<!-- HTML generated using hilite.me --><\/h3>\n<p>You can use the <code>break<\/code> statement within a <code>while<\/code> loop to exit the loop prematurely, even if the condition is still true. This allows you to terminate the loop based on a certain condition or event.<\/p>\n<p>Here&#8217;s an example of a <code>while<\/code> loop with a <code>break<\/code> statement:<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">while<\/span> i <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(i)\r\n    i <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span> i <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>:\r\n        <span style=\"color: #008800; font-weight: bold;\">break<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Output:<\/p>\n<pre>0\r\n1\r\n2<\/pre>\n<p>In this example, the <code>while<\/code> loop continues as long as the condition <code>i &lt; 5<\/code> is true. Inside the loop, the current value of <code>i<\/code> is printed, and then it is incremented by 1. The <code>if<\/code> statement checks if <code>i<\/code> is equal to 3. If the condition is true, the <code>break<\/code> statement is executed, and the loop is immediately terminated, regardless of whether the initial condition is still true.<\/p>\n<p>As a result, the loop stops when <code>i<\/code> reaches the value of 3, and the program moves on to the next line of code after the loop.<\/p>\n<p>The <code>break<\/code> statement can be useful when you want to exit a loop prematurely based on a certain condition or when you have accomplished a specific goal within the loop.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Continue Statement<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Continue Statement<\/h3>\n<p>In Python, the <code>continue<\/code> statement is used within a loop, such as a <code>while<\/code> loop, to skip the rest of the current iteration and move on to the next iteration. It allows you to control the flow of the loop and bypass certain parts of the loop&#8217;s code block.<\/p>\n<p>Here&#8217;s an example of a <code>while<\/code> loop with a <code>continue<\/code> statement:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">while<\/span> i <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    i <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span> i <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>:\r\n        <span style=\"color: #008800; font-weight: bold;\">continue<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(i)\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Output:<\/p>\n<pre>0\r\n1\r\n2\r\n4\r\n5<\/pre>\n<p>The <code>while<\/code> loop continues as long as the condition <code>i &lt; 5<\/code> is true. Inside the loop, <code>i<\/code> is incremented by 1. The <code>if<\/code> statement checks if <code>i<\/code> is equal to 3. If the condition is true, the <code>continue<\/code> statement is executed, and the remaining code within the loop&#8217;s code block is skipped for that iteration. The loop then moves on to the next iteration.<\/p>\n<p>As a result, when <code>i<\/code> is equal to 3, the <code>print(i)<\/code> statement is not executed for that iteration. The loop continues with the next iteration and prints the values of <code>i<\/code> for the other iterations.<\/p>\n<p>The <code>continue<\/code> statement can be useful when you want to skip certain iterations of a loop based on a condition. It allows you to control the flow of the loop and selectively execute specific parts of the loop&#8217;s code block.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Resources<\/h3>\n<p><a href=\"https:\/\/learnlearn.uk\/python\/continuous-repetition-loops\/\">Python Programing Challenges Topic 4 &#8211; While loops<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Indefinite Iteration Indefinite iteration, also known as an indefinite loop, is used when you want to repeat a block of code until a certain condition is met. It involves iterating until a specific condition evaluates to true or false. While Loop In Python Indefinite iteration is commonly implemented using &#8220;while&#8221; loops. Here&#8217;s an example of&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Indefinite Iteration<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Indefinite Iteration - Edexcel iGCSE Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Indefinite Iteration - Edexcel iGCSE Computer Science\" \/>\n<meta property=\"og:description\" content=\"Indefinite Iteration Indefinite iteration, also known as an indefinite loop, is used when you want to repeat a block of code until a certain condition is met. It involves iterating until a specific condition evaluates to true or false. While Loop In Python Indefinite iteration is commonly implemented using &#8220;while&#8221; loops. Here&#8217;s an example of&hellip;&nbsp;Read More &raquo;Indefinite Iteration\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\" \/>\n<meta property=\"og:site_name\" content=\"Edexcel iGCSE Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-13T20:46:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\",\"url\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\",\"name\":\"Indefinite Iteration - Edexcel iGCSE Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website\"},\"datePublished\":\"2023-06-13T20:41:51+00:00\",\"dateModified\":\"2023-06-13T20:46:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Indefinite Iteration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website\",\"url\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/\",\"name\":\"Edexcel iGCSE Computer Science\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Indefinite Iteration - Edexcel iGCSE Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/","og_locale":"en_GB","og_type":"article","og_title":"Indefinite Iteration - Edexcel iGCSE Computer Science","og_description":"Indefinite Iteration Indefinite iteration, also known as an indefinite loop, is used when you want to repeat a block of code until a certain condition is met. It involves iterating until a specific condition evaluates to true or false. While Loop In Python Indefinite iteration is commonly implemented using &#8220;while&#8221; loops. Here&#8217;s an example of&hellip;&nbsp;Read More &raquo;Indefinite Iteration","og_url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/","og_site_name":"Edexcel iGCSE Computer Science","article_modified_time":"2023-06-13T20:46:41+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/indefinite-iteration-while-loop-flowchart.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/","url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/","name":"Indefinite Iteration - Edexcel iGCSE Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website"},"datePublished":"2023-06-13T20:41:51+00:00","dateModified":"2023-06-13T20:46:41+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/indefinite-iteration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/"},{"@type":"ListItem","position":2,"name":"Indefinite Iteration"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website","url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/","name":"Edexcel iGCSE Computer Science","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Indefinite Iteration Indefinite iteration, also known as an indefinite loop, is used when you want to repeat a block of code until a certain condition is met. It involves iterating until a specific condition evaluates to true or false. While Loop In Python Indefinite iteration is commonly implemented using &#8220;while&#8221; loops. Here&#8217;s an example of&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/273"}],"collection":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":3,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/273\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/273\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/media?parent=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}