In this tutorial, we will learn basic string manipulation, control flow and other features of Ground by making a simple calculator program.
Our end goal is to create a program that computes an input, for example 33/5, 6*3, 4-10.
Getting the input
We will first need to get the input from the user. For this we will use:
This will store the user's input in the variable expression.
Indexing over a string
We want to go through the string one character at a time, and act accordingly. First, we will create an idx (index) variable, and a loop.
Now, when do we need to exit the loop? Well, if there are n characters in a string, getting the idxth character will be out of range when idx=n
This will jump to the end when idx and length are equal, i.e. we have gone through all the characters in the string.
Now, we just need to get the idxth character. Luckily this is pretty simple.