Commit e54d68c1 authored by Lartu's avatar Lartu 🐕
Browse files

LDPL Quickstart completed a little more, still lacking loops and sub-procedures

parent aa312df7
<html>
<!-- <head> section -->
<?php
$title = "LDPL in Twenty Minutes | The LDPL Programming Language";
include "head.php";
?>
<body>
<!-- Logo, name and slogan -->
<?php include "header.php"; ?>
<!-- Content section -->
<div class="bottom-content-section"><div class="container-middle" style="padding-top: 3px">
<table style="width:100%">
<tr>
<td style="padding-right: 100px; vertical-align: top;">
<h2>LDPL in Twenty Minutes</h2>
<h4>IF Statements</h4>
<p>
Things would be more interesting if we could do different things depending on the data we have.
For example, if we were coding a calculator it would be nice to ask the user if they want to add, subtract, multiply or divide and then
do what they asked for. Maybe check if the password somebody entered is right and let them log in based on that (or not). And in our
case, tell us if we are old enough to drink based on our age.
</p>
<p>
All this situations require what is called a <b>conditional</b>. A conditional is a statement that tells a programming language <i>"do this
if this happens; otherwise do this"</i>. In LDPL this is done using the <code>if - then</code> statement, together with the <code>else</code> and <code>end if</code> statements. They are used like this:
</p>
<div class="code-area" style="margin-top: 1em; margin-bottom: 1em;">
<span class="sec">DATA:</span>
<br>age is <span class="typ">number</span>
<br><span class="sec">PROCEDURE:</span>
<br><span class="sta">display</span> <span class="txt">"Hello there, how old are you?"</span> <span class="typ">crlf</span>
<br><span class="sta">accept</span> age
<br><span class="sta">if</span> age <span class="typ">is less than</span> 21 <span class="sta">then</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"You are too young to dring!"</span> <span class="typ">crlf</span>
<br><span class="sta">else</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"You are old enough to drink!"</span> <span class="typ">crlf</span>
<br><span class="sta">end if</span>
</div>
<p>
Here we use the <code>is less than</code> condition, but you can also use <code>is greater than</code>, <code>is less than or equal too</code> and <code>is greater than or equal to</code>.
You can find more information about the <code>if</code> statement <a href="https://docs.ldpl-lang.org/control-flow-statements/if-is-then" target=_blank>on the documentation</a>.
</p>
<p>
We can make conditions more complex by adding <code>else if</code> statements. These are used always <i>after</i> an <code>if</code> statement has been used and before it's been closed (<code>end if</code>).
If the condition for the first <code>if</code> statement hasn't been fulfilled, this one is checked instead. For example:
</p>
<div class="code-area" style="margin-top: 1em; margin-bottom: 1em;">
<span class="sec">DATA:</span>
<br>age is <span class="typ">number</span>
<br><span class="sec">PROCEDURE:</span>
<br><span class="sta">display</span> <span class="txt">"Hello there, how old are you?"</span> <span class="typ">crlf</span>
<br><span class="sta">accept</span> age
<br><span class="sta">if</span> age <span class="typ">is less than</span> 21 <span class="sta">then</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"You are too young to dring!"</span> <span class="typ">crlf</span>
<br><span class="sta">else if</span> age <span class="typ">is greater than</span> 100 <span class="sta">then</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"Man, you are old enough for ANYTHING."</span> <span class="typ">crlf</span>
<br><span class="sta">else</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"You are old enough to drink!"</span> <span class="typ">crlf</span>
<br><span class="sta">end if</span>
</div>
<p>
You can add as many <code>else if</code> statements as you want inside a single <code>if</code>, but always before <code>else</code> and <code>end if</code>.
</p>
<p>
If statements can also be used with the other data types LDPL provides. For example, if we wanted to check if the user is called "Bob", we could also use an <code>if</code> statement; like this:
</p>
<div class="code-area" style="margin-top: 1em; margin-bottom: 1em;">
<span class="sec">DATA:</span>
<br>name is <span class="typ">text</span>
<br>age is <span class="typ">number</span>
<br><span class="sec">PROCEDURE:</span>
<br><span class="sta">display</span> <span class="txt">"What's your name? "</span>
<br><span class="sta">accept</span> name
<br><span class="sta">if</span> name <span class="typ">is equal to</span> <span class="txt">"Bob"</span> <span class="sta">then</span>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sta">display</span> <span class="txt">"You are called Bob!"</span> <span class="typ">crlf</span>
<br><span class="sta">end if</span>
<br><span class="com"># ...etc...</span>
</div>
<p>
Now that you know how to use conditionals, there are two things left to learn: <b>loops</b> and <b>sub-procedures</b>. We'll tackle these in the remaining sections.
</p>
<p style="text-align: center;"><a href="quickstart3.php">&lt;-- Previous Page</a> | <a href="quickstart5.php">Next Page --&gt;</a></p>
</td>
<?php include "side_nav.html"; ?>
</tr>
</table>
<!-- Content section -->
<?php include "footer.html"; ?>
</div></div>
</body>
......@@ -2,12 +2,12 @@
<div class="more-section">
<b>Get Started</b> with LDPL!
<hr>
<a href="quickstart.php">LDPL in Twenty Minutes</a></p>
<p><a href="https://github.com/Lartu/ldpl#ldpl-compatible-editors">LDPL Syntax Highlighting</a></p>
<a href="quickstart.php">LDPL in Twenty Minutes</a>: A short and easy to follow introduction to the language.</p>
<p><a href="https://github.com/Lartu/ldpl#ldpl-compatible-editors">LDPL Syntax Highlighting</a>: add LDPL support to your favorite text editor.</p>
<p><a href="https://github.com/Lartu/ldpl/tree/master/examples" target=_blank>Read the Examples</a></p>
<br><b>Master</b> the language!
<hr>
<p><a href="https://docs.ldpl-lang.org/" target=_blank>Documentation</a></p>
<p><a href="https://docs.ldpl-lang.org/" target=_blank>Read the Documentation</a></p>
<p><a href="libraries.php">Libraries</a></p>
<br><b>Participate</b> in the friendly and welcoming <b>LDPL Community</b>!
<hr>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment