{"id":1186,"date":"2025-04-05T10:53:47","date_gmt":"2025-04-05T10:53:47","guid":{"rendered":"https:\/\/learnlearn.uk\/ibcs\/?page_id=1186"},"modified":"2025-04-05T10:53:47","modified_gmt":"2025-04-05T10:53:47","slug":"subprograms","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/","title":{"rendered":"Subprograms"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Introduction to Subprograms<\/h2>\n<p class=\"\">Sub-programs, also known as subroutines are self-contained blocks of code that perform a<b>\u00a0specific task<\/b>\u00a0within a larger program. They are designed to enhance modularity, reusability, and maintainability of code.<\/p>\n<p>Subprograms are first\u00a0<b>defined<\/b>\u00a0within the program. Once the function has been defined it can be executing anywhere within the program by<b>\u00a0calling<\/b>\u00a0the function, usually be writing the subprogram name, followed parentheses.<\/p>\n<pre class=\"\">def greeting(): #Here we define the subprogram\r\n\u00a0 \u00a0 print(\"hello world\")\r\ngreeting() #Here we call the subprogram<\/pre>\n<p>Subprograms can be divided into two types:\u00a0<b>functions and procedures.<\/b><\/p>\n\n<\/div><h2 class=\"tabtitle\">Functions<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Functions<\/h2>\n<p>A function is a block of code that performs a specific task and returns a value after execution.<\/p>\n<p>Functions return a\u00a0<b>result\u00a0<\/b>after execution, which can be used elsewhere in the program.Since functions return values, they can be used within expressions (e.g., mathematical calculations).<\/p>\n<h3 class=\"\">Example<\/h3>\n<pre class=\"\">def add(a, b):\r\n\u00a0 \u00a0 return a + b\r\nresult = add(3, 5)\u00a0 # Returns 8<\/pre>\n<div><\/div>\n\n<\/div><h2 class=\"tabtitle\">Procedures<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Procedures<\/h2>\n<p>A procedure (often called a subroutine) is a block of code that\u00a0<b>performs a task<\/b>\u00a0but does not return a value. Procedures do not return a result after execution; their primary goal is to carry out a task.<\/p>\n<p>Procedures are often used for performing actions like printing, modifying global variables, or interacting with the user.<\/p>\n<h3 class=\"\">Example Procedure<\/h3>\n<pre class=\"\">def greet(name):\r\n\u00a0 \u00a0 print(f\"Hello, {name}!\")\r\ngreet(\"Maria\")\u00a0 # Outputs: Hello, Maria!<\/pre>\n<div><\/div>\n\n<\/div><h2 class=\"tabtitle\">Advantages<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Advantages of Subprograms<\/h3>\n<p><strong>1. Modularity<\/strong><br \/>\nSubprograms allow for the division of complex tasks into smaller, manageable units. This modular approach makes the code easier to understand, test, and maintain.<\/p>\n<p><strong>2. Reusability<\/strong><br \/>\nSubprograms can be reused in different parts of the same program or even in different programs. This eliminates code duplication and helps save development time and effort.<\/p>\n<p><strong>3. Abstraction<\/strong><br \/>\nSubprograms reduce overall complexity by hiding the details of their internal implementation. Programmers can use them by understanding only their interface, focusing instead on higher-level logic.<\/p>\n<p><strong>4. Code Organization<\/strong><br \/>\nSubprograms help structure code into logical sections or blocks. This organization improves readability and makes debugging, updating, and navigating the codebase more efficient.<\/p>\n<\/div><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to Subprograms Sub-programs, also known as subroutines are self-contained blocks of code that perform a\u00a0specific task\u00a0within a larger program. They are designed to enhance modularity, reusability, and maintainability of code. Subprograms are first\u00a0defined\u00a0within the program. Once the function has been defined it can be executing anywhere within the program by\u00a0calling\u00a0the function, usually be writing&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Subprograms<\/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>Subprograms - IB 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\/ibcs\/subprograms\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Subprograms - IB Computer Science\" \/>\n<meta property=\"og:description\" content=\"Introduction to Subprograms Sub-programs, also known as subroutines are self-contained blocks of code that perform a\u00a0specific task\u00a0within a larger program. They are designed to enhance modularity, reusability, and maintainability of code. Subprograms are first\u00a0defined\u00a0within the program. Once the function has been defined it can be executing anywhere within the program by\u00a0calling\u00a0the function, usually be writing&hellip;&nbsp;Read More &raquo;Subprograms\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/\" \/>\n<meta property=\"og:site_name\" content=\"IB Computer Science\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/\",\"name\":\"Subprograms - IB Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\"},\"datePublished\":\"2025-04-05T10:53:47+00:00\",\"dateModified\":\"2025-04-05T10:53:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/subprograms\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IB Computer Science\",\"item\":\"https:\/\/learnlearn.uk\/ibcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Subprograms\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"name\":\"IB Computer Science\",\"description\":\"- learnlearn..uk\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\",\"name\":\"IB Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"width\":300,\"height\":41,\"caption\":\"IB Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Subprograms - IB 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\/ibcs\/subprograms\/","og_locale":"en_GB","og_type":"article","og_title":"Subprograms - IB Computer Science","og_description":"Introduction to Subprograms Sub-programs, also known as subroutines are self-contained blocks of code that perform a\u00a0specific task\u00a0within a larger program. They are designed to enhance modularity, reusability, and maintainability of code. Subprograms are first\u00a0defined\u00a0within the program. Once the function has been defined it can be executing anywhere within the program by\u00a0calling\u00a0the function, usually be writing&hellip;&nbsp;Read More &raquo;Subprograms","og_url":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/","og_site_name":"IB Computer Science","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/","url":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/","name":"Subprograms - IB Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#website"},"datePublished":"2025-04-05T10:53:47+00:00","dateModified":"2025-04-05T10:53:47+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ibcs\/subprograms\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ibcs\/subprograms\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IB Computer Science","item":"https:\/\/learnlearn.uk\/ibcs\/"},{"@type":"ListItem","position":2,"name":"Subprograms"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ibcs\/#website","url":"https:\/\/learnlearn.uk\/ibcs\/","name":"IB Computer Science","description":"- learnlearn..uk","publisher":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/ibcs\/#organization","name":"IB Computer Science","url":"https:\/\/learnlearn.uk\/ibcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","contentUrl":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","width":300,"height":41,"caption":"IB Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ibcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Introduction to Subprograms Sub-programs, also known as subroutines are self-contained blocks of code that perform a\u00a0specific task\u00a0within a larger program. They are designed to enhance modularity, reusability, and maintainability of code. Subprograms are first\u00a0defined\u00a0within the program. Once the function has been defined it can be executing anywhere within the program by\u00a0calling\u00a0the function, usually be writing&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1186"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/comments?post=1186"}],"version-history":[{"count":1,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1186\/revisions"}],"predecessor-version":[{"id":1187,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1186\/revisions\/1187"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/media?parent=1186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}