{"id":221,"date":"2022-05-10T21:41:09","date_gmt":"2022-05-10T20:41:09","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/?page_id=221"},"modified":"2022-10-18T19:23:08","modified_gmt":"2022-10-18T18:23:08","slug":"data-types-and-structures","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/data-types-and-structures\/","title":{"rendered":"Data Types and Structures"},"content":{"rendered":"<h2 style=\"color: red\">Variable<\/h2>\n<p>A variable is a storage location used to hold a value required by a program. Each variable has a unique name. The data value held in a variable may change when a program is run<img loading=\"lazy\" decoding=\"async\" class=\"wp-image-225 aligncenter\" style=\"font-size: 1rem\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10214520\/Screenshot-2022-05-10-214442-300x289.png\" alt=\"\" width=\"168\" height=\"162\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10214520\/Screenshot-2022-05-10-214442-300x289.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10214520\/Screenshot-2022-05-10-214442.png 323w\" sizes=\"auto, (max-width: 168px) 100vw, 168px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"color: red\">Data Types<\/h2>\n<p><strong><span style=\"font-size: 1rem\">The type of data that will be sored in a variable must also be defined.<\/span><\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-226\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035-300x119.png\" alt=\"\" width=\"897\" height=\"356\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035-300x119.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035-1024x406.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035-768x305.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035-624x248.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215102\/Screenshot-2022-05-10-215035.png 1192w\" sizes=\"auto, (max-width: 897px) 100vw, 897px\" \/><\/p>\n<h2 style=\"color: red\">Arrays<\/h2>\n<p>An array is an example of a <strong>data structure<\/strong>.\u00a0 Often a program will have to store lots of information at\u00a0the one\u00a0time.\u200b<\/p>\n<p>Arrays allow the programmer to store more than one\u00a0piece of data within a single data structure.\u200b\u00a0 Data that is stored in an array must\u00a0be\u00a0the same data\u00a0type, an array of integers, an of strings\u00a0etc\u200b. \u00a0Arrays must be given suitable identifiers just like a\u00a0variable<\/p>\n<p>Each piece of information stored in an array needs to be\u00a0given a number so that it can be uniquely identified.\u00a0 The number is called an \u201c<strong>index<\/strong>\u201d.\u00a0 The index always starts at zero.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-230\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516-300x22.png\" alt=\"\" width=\"900\" height=\"66\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516-300x22.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516-1024x76.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516-768x57.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516-624x47.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10215547\/Screenshot-2022-05-10-215516.png 1260w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<h2 style=\"color: red\">Creating an Array<\/h2>\n<p>Subjectlist=\u00a0[\u201cMaths\u201d,\u201dEnglish\u201d,\u201dFrench\u201d,\u201dComputing\u201d]<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-234\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329-300x236.png\" alt=\"\" width=\"978\" height=\"769\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329-300x236.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329-1024x805.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329-768x603.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329-624x490.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/05\/10220346\/Screenshot-2022-05-10-220329.png 1260w\" sizes=\"auto, (max-width: 978px) 100vw, 978px\" \/><\/p>\n<h2><span style=\"color: #ff0000\"><b>Displaying an array<\/b><\/span><\/h2>\n<p>A <b>For Loop <\/b>is an <b>arrays <\/b>best friend for one reason; the <b>counter<\/b>!<\/p>\n<p>As we should remember each <b>For Loop <\/b>has a <b>counter <\/b>and every time the loop is completed the <b>counter <\/b>increases by one. This is extremely useful when\u00a0 <b>displaying information <\/b>from <b>arrays<\/b>.<\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-576\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1.png\" alt=\"\" width=\"774\" height=\"109\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1.png 1260w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1-300x42.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1-1024x145.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1-768x108.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191928\/pic1-624x88.png 624w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/a><\/p>\n<h2><span style=\"font-weight: bold;color: #ff0000\">Populating an array<\/span><\/h2>\n<p>This allows the program to ask the user a question multiple times and saving the inputs into different <span style=\"font-weight: bold\">indexes <\/span>of the <span style=\"font-weight: bold\">array<\/span>. As the <span style=\"font-weight: bold\">counter <\/span>increases by one each time, it is perfect to use as a reference for the <span style=\"font-weight: bold\">index<\/span>.<\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-577\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2.png\" alt=\"\" width=\"1260\" height=\"394\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2.png 1260w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2-300x94.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2-1024x320.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2-768x240.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18191959\/pic2-624x195.png 624w\" sizes=\"auto, (max-width: 1260px) 100vw, 1260px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"margin: 0in;font-family: Calibri;font-size: 14.0pt\"><span style=\"font-weight: bold;color: #ff0000\">Array with a Running Total<\/span><\/h2>\n<p>The example that is shown below is a program that uses a loop to access each element of an array to calculate the total value within the array.<\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-578\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3.png\" alt=\"\" width=\"536\" height=\"198\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3.png 908w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3-300x111.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3-768x284.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/10\/18192228\/pic3-624x231.png 624w\" sizes=\"auto, (max-width: 536px) 100vw, 536px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variable A variable is a storage location used to hold a value required by a program. Each variable has a unique name. The data value held in a variable may change when a program is run &nbsp; Data Types The type of data that will be sored in a variable must also be defined. Arrays [&hellip;]<\/p>\n","protected":false},"author":79984,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-221","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/users\/79984"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":11,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/221\/revisions"}],"predecessor-version":[{"id":580,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/221\/revisions\/580"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/media?parent=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}