{"id":259,"date":"2023-06-13T19:47:30","date_gmt":"2023-06-13T19:47:30","guid":{"rendered":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?page_id=259"},"modified":"2023-06-13T19:56:24","modified_gmt":"2023-06-13T19:56:24","slug":"sequencing-and-selection","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/","title":{"rendered":"Sequencing and Selection"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Sequencing<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Sequencing<\/h3>\n<p>Sequencing refers to the order in which statements are executed. Code is typically executed in a sequential manner, line by line, from top to bottom. Each statement is executed after the previous statement has finished.<\/p>\n<p><strong>Sequencing in Python<\/strong><\/p>\n<p>Sequencing in Python is achieved by executing code on line at a time, from the top to the bottom.<\/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%;\"><span style=\"color: #888888;\"># Statement 1<\/span>\r\nx <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>\r\n\r\n<span style=\"color: #888888;\"># Statement 2<\/span>\r\ny <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>\r\n\r\n<span style=\"color: #888888;\"># Statement 3<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(y)\r\n<\/pre>\n<\/div>\n<p><strong>Sequencing in flowcharts<\/strong><\/p>\n<p>Sequencing in flowcharts is indicated using arrows, flowing from one command to the next.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-261\" src=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8.png\" alt=\"Sequencing in flowcharts is indicated using arrows\" width=\"936\" height=\"139\" srcset=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8.png 936w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8-300x45.png 300w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8-768x114.png 768w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8-930x139.png 930w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/p>\n\n<\/div><h2 class=\"tabtitle\">Selection<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Selection<\/h3>\n<p>Selection, also known as conditional execution, allows you to choose different paths of execution based on a condition. It involves using conditional statements (such as <code>if<\/code>, <code>else if<\/code>\/<code>elif<\/code>, and <code>else<\/code>) to determine which code block should be executed.<\/p>\n<p><strong>Selection in Python<\/strong><\/p>\n<p>In Python selection can be achieved through:<\/p>\n<ul>\n<li>If\/Elif\/Else statements<\/li>\n<li>Match Case Statements (Python 3.10+)<\/li>\n<\/ul>\n<p><strong>Selection in flowcharts<\/strong><\/p>\n<p>Selection in flowcharts is indicated using a diamond shape and multiple arrows<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-262\" src=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/flowchart-selection-example.png\" alt=\"\" width=\"936\" height=\"244\" srcset=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/flowchart-selection-example.png 936w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/flowchart-selection-example-300x78.png 300w, https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/flowchart-selection-example-768x200.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/p>\n\n<\/div><h2 class=\"tabtitle\">If Statements<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python If Statements<\/h3>\n<p>In Python, the <code>if<\/code> statement is used to conditionally execute a block of code based on a specified condition. It allows you to control the flow of your program based on whether a condition evaluates to <code>True<\/code> or <code>False<\/code>. Here&#8217;s the basic syntax of an <code>if<\/code> statement in Python:<br \/>\n<!-- 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%;\"><span style=\"color: #008800; font-weight: bold;\">if<\/span> condition:\r\n    <span style=\"color: #888888;\"># code block to be executed if the condition is True<\/span>\r\n<\/pre>\n<\/div>\n<p>Here&#8217;s an example that demonstrates the usage of if statement in Python:<br \/>\n<!-- 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%;\">x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">if<\/span> x <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is greater than 5\"<\/span>)\r\n<\/pre>\n<\/div>\n<p>In the above example, the if statement checks whether the condition x &gt; 5 is True. If the condition is True, the code block indented below the if statement is executed.<\/p>\n<p><strong>Else Statements<\/strong><\/p>\n<p>You can also use an else statement to specify an alternative code block to execute when the condition in the if statement is False. Here&#8217;s an example:<br \/>\n<!-- 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%;\">x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">if<\/span> x <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is greater than 5\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">else<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is not greater than 5\"<\/span>)\r\n<\/pre>\n<\/div>\n<p>In this case, since the condition x &gt; 5 is False, the code block under the else statement is executed.<\/p>\n<p><strong>Elif statements<\/strong><\/p>\n<p>You can also use elif (short for &#8220;else if&#8221;) to specify additional conditions to check. The elif statement allows you to chain multiple conditions together. Here&#8217;s an example:<\/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%;\">x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">7<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">if<\/span> x <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is greater than 10\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">elif<\/span> x <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is greater than 5 but not greater than 10\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">else<\/span>:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"x is not greater than 5\"<\/span>)\r\n<\/pre>\n<\/div>\n<p>In this example, the elif statement checks the second condition (x &gt; 5) after the first condition (x &gt; 10) is False. If both conditions are False, the code block under the else statement is executed.<\/p>\n<p>It&#8217;s important to indent the code blocks consistently within the if statement. Python uses indentation to define the scope of the code blocks, so make sure to use the same level of indentation for each block of code within the if, elif, and else statements.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Switch Statement<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Switch Statement <span style=\"color: #808080;\">(only works with Python 3.10+ )<\/span><\/h3>\n<p>Most programming language contain a swtich statement, where a number of different patterns are matched against an option. This was only added to Python in version 3.10, in the form of the match-case statements.<\/p>\n<p>The match statement allows you to match a value against multiple patterns and execute corresponding code blocks based on the matching pattern. Here&#8217;s an example of how the match statement works 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%;\">name <span style=\"color: #333333;\">=<\/span> <span style=\"color: #007020;\">input<\/span>(<span style=\"background-color: #fff0f0;\">\"please input your name: \"<\/span>)\r\n\r\nmatch name:\r\n\tcase <span style=\"background-color: #fff0f0;\">\"Arnold Schwarzenegger\"<\/span>:\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"I'll be back\"<\/span>)\r\n\tcase <span style=\"background-color: #fff0f0;\">\"James Bond\"<\/span>:\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Shaken , not stirred\"<\/span>)\r\n\tcase <span style=\"background-color: #fff0f0;\">\"Michael Corleone\"<\/span>:\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"I'm going to make him an offer he can't refuse\"<\/span>)\r\n\tcase <span style=\"background-color: #fff0f0;\">\"The Joker\"<\/span>:\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Why so serious?\"<\/span>)\r\n<\/pre>\n<\/div>\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\/python-topic-2-statements\/\">Python Challenges Topic 2<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sequencing Sequencing refers to the order in which statements are executed. Code is typically executed in a sequential manner, line by line, from top to bottom. Each statement is executed after the previous statement has finished. Sequencing in Python Sequencing in Python is achieved by executing code on line at a time, from the top&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Sequencing and Selection<\/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>Sequencing and Selection - 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\/sequencing-and-selection\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sequencing and Selection - Edexcel iGCSE Computer Science\" \/>\n<meta property=\"og:description\" content=\"Sequencing Sequencing refers to the order in which statements are executed. Code is typically executed in a sequential manner, line by line, from top to bottom. Each statement is executed after the previous statement has finished. Sequencing in Python Sequencing in Python is achieved by executing code on line at a time, from the top&hellip;&nbsp;Read More &raquo;Sequencing and Selection\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/\" \/>\n<meta property=\"og:site_name\" content=\"Edexcel iGCSE Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-13T19:56:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8.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=\"4 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\/sequencing-and-selection\/\",\"url\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/\",\"name\":\"Sequencing and Selection - Edexcel iGCSE Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website\"},\"datePublished\":\"2023-06-13T19:47:30+00:00\",\"dateModified\":\"2023-06-13T19:56:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sequencing and Selection\"}]},{\"@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":"Sequencing and Selection - 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\/sequencing-and-selection\/","og_locale":"en_GB","og_type":"article","og_title":"Sequencing and Selection - Edexcel iGCSE Computer Science","og_description":"Sequencing Sequencing refers to the order in which statements are executed. Code is typically executed in a sequential manner, line by line, from top to bottom. Each statement is executed after the previous statement has finished. Sequencing in Python Sequencing in Python is achieved by executing code on line at a time, from the top&hellip;&nbsp;Read More &raquo;Sequencing and Selection","og_url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/","og_site_name":"Edexcel iGCSE Computer Science","article_modified_time":"2023-06-13T19:56:24+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-content\/uploads\/sites\/27\/2023\/06\/Untitled-drawing-8.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/","url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/","name":"Sequencing and Selection - Edexcel iGCSE Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website"},"datePublished":"2023-06-13T19:47:30+00:00","dateModified":"2023-06-13T19:56:24+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/sequencing-and-selection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/"},{"@type":"ListItem","position":2,"name":"Sequencing and Selection"}]},{"@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":"Sequencing Sequencing refers to the order in which statements are executed. Code is typically executed in a sequential manner, line by line, from top to bottom. Each statement is executed after the previous statement has finished. Sequencing in Python Sequencing in Python is achieved by executing code on line at a time, from the top&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/259"}],"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=259"}],"version-history":[{"count":5,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/259\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/259\/revisions\/267"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/media?parent=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}