A variable is like a labeled box where you store information.
Think of SET as putting
something in a box!
SET score TO 100
SET is_fun TO true
Wrap text in double quotes: "Hello"
Just write the number: 42 or 3.14
Use true or false (no quotes!)
Use square brackets: [1, 2, 3]
my_score.🧠 Quick Check! How do you create a variable in FLang?
DISP (short for Display) lets you print things to the screen. It's like telling the computer to say something out loud!
DISP score
DISP "Your score is: " + score
+ operator to join text and variables together!Sometimes we want the computer to make choices. We use IF, ELIF (else-if), and ELSE for this!
IF age > 12:
DISP "You are a teenager!"
ELIF age < 5:
DISP "You are a toddler!"
ELSE:
DISP "You are just right!"
> Greater than< Less than>= Greater or
equal<= Less or equal= Equal to
& means AND| means OR! means NOT
: at the end of IF, ELIF, and ELSE lines!🧠 What does ELIF stand for?
Loops let the computer repeat actions many times. There are two kinds of loops in FLang!
Use when you know how many times to repeat.
Use when you repeat until something changes.
FOR range( 1, 6 ) AS i:
DISP i
-- Loop through a list
SET fruits TO [ "apple", "banana", "mango" ]
FOR fruits AS fruit:
DISP fruit
-- WHILE loop
SET counter TO 0
WHILE counter < 3:
DISP "Still going!"
SET counter TO counter + 1
continue)
break)
A list is a collection of items stored in one variable. Think of it like a bag holding many things!
-- Get the first item (index 0)
DISP my_list[0] -- prints 10
-- Loop through the list
FOR my_list AS item:
DISP item
A function is a reusable block of code you name and call whenever you need it. Use DEF to define one!
DISP "Hello " + name + "!"
say_hello("Sam")
say_hello("Alex")
-- Function with RETURN
DEF add(a, b):
RETURN a + b
SET result TO add(5, 3)
DISP result -- prints 8
Use ASK to ask the user a question and store their answer in a variable!
SET age TO ASK INT "How old are you? "
-- Ask for text
SET name TO ASK STR "What is your name? "
DISP "Nice to meet you, " + name + "!"
Asks for a whole number. Perfect for scores, ages, counts!
Asks for text. Perfect for names, answers, messages!
Save your code in a file ending with .fun and run it like this:
🎉 You finished the lessons!
Now go to the Explore page to discover all the built-in functions, or check out the GitHub repo to download FLang!