Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.93 KB

c4.md

File metadata and controls

48 lines (34 loc) · 1.93 KB

Chapter 4: Hello World!

In the previous chapter we used numbers to check if the door we created was open or closed.
Why not a simple boolean I hear some folks asking? Simple: The only available data types in YOLOL are numbers (integers and decimals) and strings (a list of characters).
So in reality using false and true means nothing other than trying to assign something to a field, however not a boolean.

Step #1
To get to some coding, write var="Hello!" into the first line and try running it!

SNIPPET

As you will see, a local variable called var will be initialised with the value Hello!. Now let's try and add another word to the string using string operations.
String operations will manipulate an existing string to add or remove parts to/ from it. More about operators and their usage in the official documentation!

Step #2:
Write var+="World!" into the second line and execute the snippet!

SNIPPET

var="Hello!"

As you may have noticed, the resulting string has an excess questionmark in between the two words. Why?

The operator += appends or adds something to the specified variable. It does not replace or remove characters, thus the questionmark after Hello remains. An easy fix would obviously be to change var to just Hello before doing anything with it, but that would be boring! Here we can introduce another operator: --

Step #3:
Write var-- in between the two lines and let the snippet run again!

SNIPPET

var="Hello!"
var+="World!"

As you see, there's still a space missing in between the words. I'll leave that one for you to figure out though!

Step #4:
Try to get a space in between the two words!

SNIPPET

var="Hello!"
var--
var+="World!"

Previous Chapter Next Chapter