{
    "componentChunkName": "component---src-components-layout-mdx-layout-tsx",
    "path": "/language/beginner/lists-and-functions",
    "result": {"data":{"site":{"siteMetadata":{"title":"Toit documentation"}},"mdx":{"body":"const _excluded = [\"components\"];\n\nfunction _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }\n\nfunction _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }\n\nfunction _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nconst _frontmatter = {};\n\nconst makeShortcode = name => function MDXDefaultShortcode(props) {\n  console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n  return mdx(\"div\", props);\n};\n\nconst Expandable = makeShortcode(\"Expandable\");\nconst layoutProps = {\n  _frontmatter\n};\nconst MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  let {\n    components\n  } = _ref,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", {\n    \"id\": \"lists-and-functions\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h1\",\n    \"href\": \"#lists-and-functions\",\n    \"aria-label\": \"lists and functions permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Lists and functions\"), mdx(\"p\", null, \"This is lesson 2 of the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/beginner\"\n  }, \"beginner tutorial\"), \". It assumes you\\nhave run the first lesson's examples and can use a variable, print a string,\\nand make a decision with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"if\"), \".\"), mdx(\"p\", null, \"We will first report several temperatures, then give the reporting operation a\\nname so we can reuse it. Keep using \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"report.toit\"), \"; each example replaces the\\nwhole file.\"), mdx(\"h2\", {\n    \"id\": \"store-several-readings\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#store-several-readings\",\n    \"aria-label\": \"store several readings permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Store several readings\"), mdx(\"p\", null, \"A \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"list\"), \" holds values in order. Square brackets surround its values, and commas\\nseparate them. Here is a list containing three temperatures:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"main:\\n  readings := [21, 26, 24]\\n  print readings\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"[21, 26, 24]\"), \". Add \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"28\"), \" after \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24\"), \", separated by a comma, and run\\nit again. You should see four values in the printed list.\"), mdx(\"h2\", {\n    \"id\": \"do-something-for-each-reading\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#do-something-for-each-reading\",\n    \"aria-label\": \"do something for each reading permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Do something for each reading\"), mdx(\"p\", null, \"We want to print each temperature on its own line. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"readings.do:\"), \" runs a piece\\nof code once for each value in the list:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"main:\\n  readings := [21, 26, 24]\\n  readings.do: |temperature|\\n    print \\\"Temperature: $temperature C\\\"\\n\")), mdx(\"p\", null, \"The output is:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-text\"\n  }, \"Temperature: 21 C\\nTemperature: 26 C\\nTemperature: 24 C\\n\")), mdx(\"p\", null, mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"|temperature|\"), \" gives a name to the value for the current run. On the first run\\nit is \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"21\"), \", on the second \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"26\"), \", and on the third \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24\"), \". The indented code after\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"do:\"), \" is called a \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"block\"), \". Here that block contains one instruction.\"), mdx(\"p\", null, \"Add another reading and check that it produces another output line. Try \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"[]\"), \",\\nan empty list. There are no values to process, so the block does not run and\\nnothing is printed.\"), mdx(\"h2\", {\n    \"id\": \"add-a-decision-for-each-reading\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#add-a-decision-for-each-reading\",\n    \"aria-label\": \"add a decision for each reading permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Add a decision for each reading\"), mdx(\"p\", null, \"The block can contain several instructions. Put the first lesson's decision\\ninside it:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"main:\\n  readings := [21, 26, 24]\\n  readings.do: |temperature|\\n    if temperature >= 25:\\n      print \\\"$temperature C: Warm\\\"\\n    else:\\n      print \\\"$temperature C: Comfortable\\\"\\n\")), mdx(\"p\", null, \"Expected output:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-text\"\n  }, \"21 C: Comfortable\\n26 C: Warm\\n24 C: Comfortable\\n\")), mdx(\"p\", null, \"Notice the indentation. The \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"if\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"else\"), \" belong to the block. Their \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print\"), \"\\ninstructions are indented one level further, because each belongs to one side\\nof the decision.\"), mdx(\"p\", null, \"Try \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"[25, 10]\"), \". Predict both messages, then run the program.\"), mdx(\"h2\", {\n    \"id\": \"give-the-operation-a-name\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#give-the-operation-a-name\",\n    \"aria-label\": \"give the operation a name permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Give the operation a name\"), mdx(\"p\", null, \"We might want to report a temperature from somewhere other than this list.\\nA \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"function\"), \" lets us name an operation and call it wherever we need it.\"), mdx(\"p\", null, \"We already have a function, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"main\"), \". Add another called \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading\"), \":\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"print-reading temperature:\\n  if temperature >= 25:\\n    print \\\"$temperature C: Warm\\\"\\n  else:\\n    print \\\"$temperature C: Comfortable\\\"\\n\\nmain:\\n  print-reading 21\\n  print-reading 26\\n\")), mdx(\"p\", null, \"This prints:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-text\"\n  }, \"21 C: Comfortable\\n26 C: Warm\\n\")), mdx(\"p\", null, \"The two lines under \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"main\"), \" \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"call\"), \" the function. Each call runs its body using\\nthe supplied temperature. In \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading 21\"), \", the supplied value \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"21\"), \" is\\nan \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"argument\"), \". The name \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"temperature\"), \" in the function definition is a \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"parameter\"), \".\"), mdx(\"p\", null, mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading\"), \" contains a hyphen because that is a normal part of a Toit name.\\nThe function definitions start at the left edge of the file; their bodies are\\nindented. Defining \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading\"), \" does not run it. A call runs it.\"), mdx(\"p\", null, \"Add \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading 25\"), \" under \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"main\"), \" and check the result.\"), mdx(\"h2\", {\n    \"id\": \"combine-the-function-and-the-list\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#combine-the-function-and-the-list\",\n    \"aria-label\": \"combine the function and the list permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Combine the function and the list\"), mdx(\"p\", null, \"The list block can call the function for every reading. The function keeps\\nthe reporting instructions in one place:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"print-reading temperature:\\n  if temperature >= 25:\\n    print \\\"$temperature C: Warm\\\"\\n  else:\\n    print \\\"$temperature C: Comfortable\\\"\\n\\nmain:\\n  readings := [21, 26, 24]\\n  readings.do: |temperature|\\n    print-reading temperature\\n\")), mdx(\"p\", null, \"The output is the same three-line report as before. To change how temperatures\\nare reported, edit \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading\"), \". To change which temperatures are reported,\\nedit the list in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"main\"), \".\"), mdx(\"h2\", {\n    \"id\": \"pass-a-second-argument\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#pass-a-second-argument\",\n    \"aria-label\": \"pass a second argument permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Pass a second argument\"), mdx(\"p\", null, \"Different reports may use different limits. Add a second parameter, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"limit\"), \",\\nso callers can choose it:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"print-reading temperature limit:\\n  if temperature >= limit:\\n    print \\\"$temperature C: Warm\\\"\\n  else:\\n    print \\\"$temperature C: Comfortable\\\"\\n\\nmain:\\n  readings := [21, 26, 24]\\n  readings.do: |temperature|\\n    print-reading temperature 24\\n\")), mdx(\"p\", null, \"Now both \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"26\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24\"), \" are reported as warm. Spaces separate the call's arguments:\\nthe first is the temperature, and the second is the limit. Commas belong between\\nthe values in a list, not between a function's arguments.\"), mdx(\"h2\", {\n    \"id\": \"name-an-argument\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#name-an-argument\",\n    \"aria-label\": \"name an argument permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Name an argument\"), mdx(\"p\", null, \"At the call site, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print-reading temperature 24\"), \" does not tell us what \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24\"), \"\\nmeans. A \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"named argument\"), \" makes that purpose visible. Write \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"--limit\"), \" in both\\nthe function definition and its calls:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"print-reading temperature --limit=25:\\n  if temperature >= limit:\\n    print \\\"$temperature C: Warm\\\"\\n  else:\\n    print \\\"$temperature C: Comfortable\\\"\\n\\nmain:\\n  print-reading 24 --limit=24\\n  print-reading 24\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24 C: Warm\"), \", then \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24 C: Comfortable\"), \". The first call chooses a\\nlimit of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"24\"), \". The second leaves it out, so the function uses the \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"default\"), \"\\nvalue \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"25\"), \" from its definition. Inside the function, the name is just \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"limit\"), \".\"), mdx(\"p\", null, \"Named arguments are common in Toit. They help us read a call without looking\\nup what each position means. We will use this version in the next exercise.\"), mdx(\"h2\", {\n    \"id\": \"practice\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#practice\",\n    \"aria-label\": \"practice permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Practice\"), mdx(\"p\", null, \"Create two lists named \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"kitchen\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"bedroom\"), \". Print a room heading, then report\\nthat room's readings. Use a limit of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"25\"), \" for the kitchen and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"23\"), \" for the bedroom.\"), mdx(Expandable, {\n    title: \"Solution: report two rooms\",\n    mdxType: \"Expandable\"\n  }, mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"print-reading temperature --limit=25:\\n  if temperature >= limit:\\n    print \\\"$temperature C: Warm\\\"\\n  else:\\n    print \\\"$temperature C: Comfortable\\\"\\n\\nmain:\\n  kitchen := [21, 26]\\n  bedroom := [22, 24]\\n  print \\\"Kitchen\\\"\\n  kitchen.do: |temperature|\\n    print-reading temperature --limit=25\\n  print \\\"Bedroom\\\"\\n  bedroom.do: |temperature|\\n    print-reading temperature --limit=23\\n\")), mdx(\"p\", null, \"Expected output:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-text\"\n  }, \"Kitchen\\n21 C: Comfortable\\n26 C: Warm\\nBedroom\\n22 C: Comfortable\\n24 C: Warm\\n\"))), mdx(\"p\", null, \"This is a useful stopping point: you can process a collection and reuse code.\\nWhen you are ready, continue with \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/beginner/objects\"\n  }, \"objects\"), \" to keep\\neach room's settings and readings together. To try the language on hardware,\\nfollow \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/getstarted/device\"\n  }, \"Run on your device\"), \".\"));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{"items":[{"url":"#lists-and-functions","title":"Lists and functions","items":[{"url":"#store-several-readings","title":"Store several readings"},{"url":"#do-something-for-each-reading","title":"Do something for each reading"},{"url":"#add-a-decision-for-each-reading","title":"Add a decision for each reading"},{"url":"#give-the-operation-a-name","title":"Give the operation a name"},{"url":"#combine-the-function-and-the-list","title":"Combine the function and the list"},{"url":"#pass-a-second-argument","title":"Pass a second argument"},{"url":"#name-an-argument","title":"Name an argument"},{"url":"#practice","title":"Practice"}]}]}}},"pageContext":{"title":"Lists and functions","id":"5e8e342d-07c6-53de-bd46-792b291cc02c"}},
    "staticQueryHashes": ["2197327828"]}