Skip to content
← Back to Community
LOLCODE ~ Complete Tutorial
Profile icon
KobeFF

LOLCODE ~ The Basics...

LOLCODE is an esoteric programming language inspired by the funny things on the Internet. It is designed to test the boundaries of programming language design. This tutorial provides a basic level understanding of the LOLCODE programming language.

This tutorial is meant for people who want to explore beyond general boring programming syntax. Readers of this tutorial can learn the programming language in simple and easy ways.

Programming experience recommended.

Before we get started...

To start your program, write HAI 1.2. This means that your program is running LOLCODE verison 1.2, the newest version. End your program with KTHXBYE. Anything written after the ending of your program will return an error upon execution.

Example:

HAI 1.2   BTW Write your code here! KTHXBYE

*IMPORTANT: Every syntax in LOLCODE is in all caps. Make sure that you write it like that, otherwise your LOLCODE program will not run.

1) Printing Statements

To print a string, you use the function VISIBLE. Make sure that you make it ALL CAPS! (Every syntax in LOLCODE is in all caps). Put your string in double quotes.

Example:

VISIBLE "Hello World!"

Output:

Hello World!

2) Comments

Unlike other languages, LOLCODE comments start with the keyword BTW (Slang for 'By the way'). Anything after the BTW is ignored.

Example:

BTW The following code will not execute BTW VISIBLE "Hello World!"

Multi-line comments in LOLCODE start with the keyword OBTW(Short for 'Oh, by the way') and end with TLDR.

Example:

OBTW   This is a comment   Split between   Multiple lines! TLDR

*The indentation isn't needed, I just use it because it makes it easier to read.

3) Variables

To declare a variable, use the I HAVE A statement.

Example:

I HAVE A food BTW my variable is named 'food' VISIBLE "Yummy!"

Output:

Yummy!

To assign a variable a value, use the keyword ITZ after the declaration of the variable.

Example:

I HAVE A food ITZ "Hamburgers" I HAVE A number ITZ 100 VISIBLE food VISIBLE number

*When we are giving the variable food a value of "Hamburgers", we use double quotes around the string, and when we are giving number a value of 100 (an integer), we do not.

You can also assign a variable a value with the R function ('R' stands for 'are').

I HAVE A apple apple R "Yummy" BTW apple has the value of "Yummy"

Alternatively, you can also change the value of a variable with the R statement too.

I HAVE A number ITZ 34 BTW 'number' equals 34 number R 57 BTW 'number' now equals 57 VISIBLE number BTW Prints out 57, not 34

LOLCODE does not allow use of spaces, dashes, or other symbols while naming a variable.

Example:

I HAVE A number$ BTW Returns a error because our variable 'number$' contains '$'

Here are some of the rules for valid and invalid names for variables in LOLCODE:

  • The name should always begin with an alphabet. For example, name, Name are valid.
    • The name of a variable cannot begin with a digit. For example, 2var is invalid.
    • The name of a variable cannot begin with a special character.
    • A variable can contain _ or a digit anywhere inside its name, except at the starting index. For example, name2_m is a valid name.

4) Types

Currently, the variable types in LOLCODE are:

- Strings (YARN) - Integers (NUMBR) - Floats (NUMBAR) - Booleans (TROOF) - Arrays (BUKKIT)

In LOLCODE the variable type is handled dynamically by the compiler. If a variable does not have an initial value, it is called untyped (known as NOOB in LOLCODE).

I HAVE A string ITZ "Hello World!" BTW 'string' as a value type of 'YARN'

*Boolean values in LOLCODE are WIN and FAIL instead of True and False, like in many other languages.

5) NOOB values

When a variable is declared, but does not have a value, it's value type is untyped, or NOOB.

I HAVE A variable BTW 'variable' does not have a value, so it's value type is NOOB

A variable is not a NOOB type as soon as a value is assigned to it.

I HAVE A variable BTW 'variable' has a value type of NOOB variable R 100 BTW 'variable' value type is now NUMBR

And also...

I HAVE A decimal ITZ 3.4 BTW 'decimal' immediately has a value type of NUMBAR

6) Operators

Following are the basic mathematical operations in LOLCODE:

SUM OF [ AN ]

Voters
Profile icon
LonelyTeapot
Profile icon
firedragondnd
Profile icon
parkerslv
Profile icon
dudeactualdev
Profile icon
shayray800
Profile icon
EpicGamer007
Profile icon
CoolGuy27
Profile icon
Kookiez
Profile icon
LeandroAraiza
Profile icon
zplusfour
Comments
hotnewtop
Profile icon
SixBeeps

I love how serious this tutorial is compared to the code

Profile icon
KobeFF
Profile icon
awesome10

@KobeFF CODE

Profile icon
Jakman

Can you write an os in LOLCODE?

Profile icon
KobeFF

@Jakman I don't think so... I think you have to use C#.

Profile icon
Techcraft7

@KobeFF Make an interpreter in C# with Cosmos OS and then write the operating system in LOLCODE and put it throught the interpreter, you might need custom syntax for file management, colors, etc.

Profile icon
Jakman

@KobeFF That can be done

Profile icon
KobeFF
Profile icon
Techcraft7

@KobeFF Not gonna lie it will be a bit harder because you would have to plug System.Linq because Cosmos does not support i

Profile icon
KobeFF

@Techcraft7Gamez Yes... So I'm not gonna do it... :P

Profile icon
Jakman

@KobeFF I will help since it is C#.

Profile icon
KobeFF

@Jakman Mkay, thanks

Profile icon
CodingCactus

lol, LOLCODE is funny

Profile icon
KobeFF
Profile icon
firefish

@CodingCactus lol (lol (lol (lol)))

Profile icon
Bookie0

Nice.i like it LOL

Profile icon
BobNeo

lol

Profile icon
KobeFF
Profile icon
KimiTian08

ITZ HAS NO HAVE

Profile icon
[deleted]

Nice tutorial! One thing, though: you say "syntax" instead of "keyword" or "function". Syntax is everything about the language, not just one part, like VISIBLE.

Profile icon
KobeFF

@sugarfi Ok, Ill change that. Thanks!

Profile icon
[deleted]

@KobeFF cool!

Profile icon
lhk1

Why is defining functions not implemented? HOW IZ I

Profile icon
PhoenixGeorge

@lhk1 implemented as HOW DUZ I

Profile icon
Kookiez

hmm, i think itz supposed to be I HAS A, not I HAVE A... but other than that, good tutorial!

Profile icon
KobeFF

@Kookiez Hmm, I'll look into that... Thanks for pointing that out! Though at least in my code, it works fine with I HAVE A.

Profile icon
Kookiez

@KobeFF huh weird... it gives a error when i type I HAVE A, but it doesn't with I HAS A.

Profile icon
KobeFF

@Kookiez LOL! idk honestly XD

Profile icon
Kookiez
Profile icon
studentAlfredAl

lol

Profile icon
[deleted]

HARD :)

Profile icon
KobeFF

@Zuhdi28 yes...

Profile icon
Jackolanternexe

Your avatar makes me want to VISIBLE "Dance!"

Profile icon
KobeFF

@Jackolanternexe Lol, me too!

Profile icon
sylashur

brainf*** gang here, LOLCODE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++.+++.

Profile icon
KobeFF
Profile icon
mmf045

this is cool but wierd! I like it

Profile icon
KobeFF

@mmf045 Thanks :)

Profile icon
mmf045

@KobeFF yours welcomes

Profile icon
KobeFF