You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><strong>if ... then ... else ...</strong> statements are designed to efficiently route program flow/functionality, via boolean logic, to one of two paths. These are generally decided by logical and numeric comparisons.</p>
60
60
<p>Examine the following block of code:</p>
61
61
<pre><codeclass="hljs css language-ocaml"><spanclass="hljs-keyword">if</span> a <= b
<p><strong>If</strong> the value of <strong>'a' is less than or equal to 'b'</strong>, the entire clause will return <em>True</em>. Otherwise, the clause will return <em>False</em>.
66
-
This can be used to control the behavior of a function under variable situations.</p>
65
+
<p><strong>If</strong> the value of <strong>'a' is less than or equal to 'b'</strong>, the entire clause will return the value of <em>b-a</em>. Otherwise, the clause will return the value of <em>a-b</em>.
66
+
This can be used to control the behavior of a function under variable situations. You can control the flow and structure of programs to make them more interesting and outputs will finally depend on inputs.
67
+
for example the return value of the previous control logic is different if the values of 'a' and 'b' are switched</p>
<p><strong>match ... with ...</strong> statements are designed to efficiently route program flow/functionality to one of many paths. These are typically used for handling more complex cases than <em>if ... then ... else ...</em> statements.</p>
70
+
<p><strong>match ... with ...</strong> statements are designed to efficiently route program flow/functionality to one of many paths. These are typically used for handling more complex cases than <em>if ... then ... else ...</em> statements. The parameter being matched with can be compared by type, value, etc. and is matched with each case you set up from the top to bottom. If all of the cases fail ie. the parameter doesn't meet any of the match cases then the default value is returned from the function.</p>
70
71
<p>Examine the following code:</p>
71
72
<pre><codeclass="hljs css language-ocaml"><spanclass="hljs-keyword">match</span> x <spanclass="hljs-keyword">with</span>
0 commit comments