{"id":202,"date":"2022-05-23T14:29:03","date_gmt":"2022-05-23T13:29:03","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/?page_id=202"},"modified":"2024-09-03T10:25:31","modified_gmt":"2024-09-03T09:25:31","slug":"scope-of-a-variable","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/scope-of-a-variable\/","title":{"rendered":"Scope of a Variable"},"content":{"rendered":"<h2 style=\"color: red\">Scope of a Variable<\/h2>\n<p>The scope of a variable refers to <strong>where the variable can be used<\/strong>.<\/p>\n<p>Throughout the <strong>whole program (Global) <\/strong>or <strong>limited to only one module (Local). <\/strong><\/p>\n<p>It is important to make sure that variables are only used or altered when the programmer wants them to be.<\/p>\n<h2 style=\"color: red\">Global Variables<\/h2>\n<p><strong>Global Variables (<\/strong>which we have used at N5<strong>) <\/strong>can be used throughout the whole program in every module. Although this is easier to program it does mean that<\/p>\n<ul>\n<li><span style=\"color: #ff0000\"><strong>variable is open to being <\/strong><strong>accidentally over written or changed<\/strong>. <\/span><\/li>\n<li><span style=\"color: #ff0000\"><strong>use more memory within the RAM as they need to be stored throughout the duration of the program.<\/strong><\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-212\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009-300x203.png\" alt=\"\" width=\"754\" height=\"510\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009-300x203.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009-1024x693.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009-768x520.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009-624x422.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172047\/Screenshot-2022-05-23-172009.png 1260w\" sizes=\"auto, (max-width: 754px) 100vw, 754px\" \/><\/p>\n<h2 style=\"color: red\">Local Variables<\/h2>\n<p><strong>Local variables <\/strong>can only be used in a specific module.<\/p>\n<p>This means that variables are:<\/p>\n<ul>\n<li><span style=\"color: #ff0000\">more secure and <strong>will not be changed unexpectedly <\/strong><\/span><\/li>\n<li><span style=\"color: #ff0000\"><strong>take up less memory within the RAM<\/strong> as they only need to be stored for the duration of that specific module \u00a0<\/span><\/li>\n<li><span style=\"color: #ff0000\">\u00a0it allows the module to be more \u201cportable\u201d. This means that the <strong>module can be used again within other programs<\/strong>\u00a0<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-213\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817-300x184.png\" alt=\"\" width=\"753\" height=\"462\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817-300x184.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817-1024x629.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817-768x472.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817-624x383.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23172100\/Screenshot-2022-05-23-171817.png 1260w\" sizes=\"auto, (max-width: 753px) 100vw, 753px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scope of a Variable The scope of a variable refers to where the variable can be used. Throughout the whole program (Global) or limited to only one module (Local). It is important to make sure that variables are only used or altered when the programmer wants them to be. Global Variables Global Variables (which we [&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-202","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/users\/79984"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":4,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/202\/revisions"}],"predecessor-version":[{"id":347,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/202\/revisions\/347"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/media?parent=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}