Skip to content
Sign upLog in
← Back to Community

A Crash Course in LOLCODE 🐱

Profile icon
minermaniac447

A Crash Course in LOLCODE


OHAI! This is a crash course in the beautiful programming language known as LOLCODE! LOLCODE is a great language, and while it is similar to many other programming languages, trying to learn it may confuse some people because of the syntax. For this tutorial, any time I say [variable1], [variable2], or [variable], as long as I'm not talking about initializing a variable, you can put a value instead.

Creating a new program

To begin a program, you need to have the line HAI 1.2. This will declare that it's a LOLCODE program that's written in LOLCODE 1.2. The last line in the program must be KTHXBYE.

Comments

There are two different ways of doing commenting - BTW and OBTW. The differences are shown below:

BTW This is a one-line comment. OBTW This is a multi-line comment TLDR

The indentation is not necessary, but it makes it easier to read.

Variables

Variables are dynamically typed in LOLCODE, so you don't have to give them a type when declared. To declare a variable, use I HAS A [variable]. However, if you do want to give it a type, you can use I HAS A [variable] ITZ A [type]. There are 4 usable types of variables:

  • TROOF (a boolean - WIN or FAIL, corresponding to true or false.)
  • NUMBR (an integer - whole numbers)
  • NUMBAR (a float - decimal places)
  • YARN (a string - text, defined by "")

Variable names are case-sensitive, so INT is different from Int. You can use capital and lowercase letters, underscores, and numbers - as long as neither underscores nor numbers begin the variable name. To assign one variable to another, use [variable 1] R [variable 2].

Concatenation

It's very simple to concatenate YARNS in LOLCODE - you use SMOOSH [variables to concatenate, seperated by AN] MKAY. It will cast any input given to it to a YARN before concatenating. See below for an example.

I HAS A VAR1 ITZ "Hi" I HAS A VAR2 ITZ 1234 I HAS A VAR3 ITZ WIN I HAS A VAR4 ITZ SMOOSH VAR1 AN VAR2 AN VAR3 MKAY VISIBLE VAR4 BTW The output will be Hi1234WIN

Casting

There are a couple different ways of casting a variable from 1 type to another. The first is MAEK [variable] A [type]. This will attempt to cast from whatever type the variable is to the desired type. However, this will not work if it's illogical - for instance, trying to cast letters into a NUMBR or NUMBAR. To cast a variable to a different type and save the output in a different variable, use [variable 1] R MAEK [variable 2] A [type].

Expressions

There are 3 different types of expressions in LOLCODE - Math, Boolean, and Comparison. The basic form for all expressions is either [expression] [variable] or [expression] [variable1] AN [variable2].

Math

In LOLCODE, you have all the typical expression types - addition, subtraction, multiplication, division, and modulus (remainder), as well as some less-common ones - min (returns the value of the smaller of 2 variables) and max (returns the value of the larger of 2 variables). If either variable is a YARN and has a decimal, it is cast to a NUMBAR for the calculation. If it doesn't have a decimal, it's cast to a NUMBR. If both variables used are NUMBRs, then integer math is performed. If one or both are NUMBARS, floating floating point math is invoked. See below for a list of math expressions:

SUM OF [variable 1] AN [variable 2] BTW This is addition DIFF OF [variable 1] AN [variable 2] BTW This is subtraction PRODUKT OF [variable 1] AN [variable 2] BTW This is multiplication QUOSHUNT OF [variable 1] AN [variable 2] BTW This is division MOD OF [variable 1] AN [variable 2] BTW This is modulus (remainder) BIGGR OF [variable 1] AN [variable 2] BTW This returns the bigger variable's value SMALLR OF [variable 1] AN [variable 2] BTW This returns the smaller variable's value

Boolean

The boolean expressions work pretty much as you would expect, comparing WINs and FAILs. You can use and, or, xor, and not. Any value passed to this is cast to a TROOF. See below for the complete list:

BOTH OF [variable 1] AN [variable 2] BTW This is an and statement EITHER OF [variable 1] AN [variable 2] BTW This is an or statement WON OF [variable 1] AN [variable 2] BTW This is an XOR statement NOT [variable] BTW This is a not statement ALL OF [variable 1] AN ... MKAY BTW This is an infinite and statement, keep adding variable names and ANs to check more ANY OF [variable 1] AN ... MKAY BTW This is an infinite or statement, see above

Comparisons

This is very similar to boolean expressions - it takes in 2 variables and checks if they're either the same or different. However, it doesn't have to be 2 TROOFS, but they do have to be the same type. "9" and 9 will NOT be recognized as the same. See below for examples

BOTH SAEM [variable 1] AN [variable 2] BTW returns WIN if variable 1 == variable 2 DIFFRINT [variable 1] AN [variable 2] BTW returns WIN if variable 1 != variable 2 BOTH SAEM [variable 1] AN BIGGR OF [variable 1] AN [variable 2] BTW variable 1 >= variable 2 BOTH SAEM [variable 1] AN SMALLR OF [variable 1] AN [variable 2] BTW variable 1 <= variable 2 DIFFRINT [variable 1] AN BIGGR OF [variable 1] AN [variable 2] BTW variable 1 < variable 2 DIFFRINT [variable 1] AN SMALLR OF [variable 1] AN [variable 2] BTW variable 1 > variable 2

Printing

To output text, you have to use the VISIBLE [output] command. This can also be used with variables by using VISIBLE [variable]. See below for examples:

VISIBLE "Invisible" VISIBLE INT

Input

To get input from the user, you can use GIMMEH [variable]. For this, you MUST specify a variable because that is where the output is stored. GIMMEH stores input as a YARN, so if you want to get a NUMBR or NUMBAR you have to cast it as such.

Conditionals

Creating conditionals is fairly straightforward in LOLCODE. There are 2 basic formats - one utilizing TROOFs, and one utilizing other types of variables. To create a conditional using TROOFs, use the following:

[expression], O RLY? YA RLY BTW This code will execute if the result of [expression] is WIN NO WAI BTW This code will execute if the result of [expression] is FAIL OIC

To create a conditional using other variable types is a little more involved. Basically, OMG [value] is the same as checking if the expression is equal to [value], and OMGWTF is an else. To end a statement, you must put GTFO.

[expression], WTF? OMG 5 BTW This code will execute if the result of [expression] is 5 GTFO OMG 91 OMG 21 BTW This code will execute if the result of [expression] is 91 or 21 GTFO OMGWTF BTW This code will execute if the result of [expression] is not 5, 91, or 21 OIC

Loops

Loops are a somewhat confusing beast at first, but actually aren't that hard. First, you need IM IN YR [label for the loop - I would recommend just calling it LOOP]. Then, if you want to increase the iterator variable have UPPIN YR [variable], and if you want to decrease the iterator variable have NERFIN YR [variable]. Finally, if you want to go until a certain value, use TIL [expression], and if you want to go while a certain expression is true, use WILE [expression]. To end the loop, use IM OUTTA YR [label]. See below for an example:

I HAS A ITERATOR ITZ 0 IM IN YR LOOP UPPIN YR ITERATOR TIL BOTH SAEM ITERATOR AN 9 VISIBLE ITERATOR IM OUTTA YR LOOP BTW This will output 0 through 8, and then stop before printing 9.

Conclusion

Aaaand that's pretty much everything I could possibly find on the internet about LOLCODE... There is documentation for functions and BUKKITs (arrays), but I couldn't get them to work and so I decided against detailing them. If you still want MOAR LOLCODE documentation, go here, here, or here. If you want a fairly simple random python with turtle spiral generator, go check out my tutorial for that here. If you want a super long tutorial about how to make your own game using only python with turtle graphics, go here. If you liked this tutorial, feel free to leave an upvote. Thanks! :)

Voters
Profile icon
Palitin
Profile icon
MaxwellHyun
Profile icon
SMeunier123
Profile icon
roslynchat
Profile icon
ArgentavisMagnus
Profile icon
AppleiPad556
Profile icon
anymous
Profile icon
daikonic
Profile icon
mmf045
Profile icon
fluffykitty421
Comments
hotnewtop
Profile icon
OwenBradstreet

This is a great tutorial, covering most of the language.
LOLCODE can be hard to understand, I think you explained it quite well. You have my upvote!

Profile icon
minermaniac447

@OwenBradstreet
Thanks! I'm glad you liked the tutorial! :D

Profile icon
AquaMarine0421

I HAS A COMPLIMENT FOR U
ITZ "YOU HAVE A FANTASTIC TUTORIAL!!"

Profile icon
AquaMarine0421

I dink LOLCODE is really fun

Profile icon
brooc210

@AquaMarine0421
Why not put that in code?

Profile icon
MidnighttheHusky
Profile icon
brooc210

SVG images are not supported

no lolcats were harmed in the making of this tutorial
SVG images are not supported
!

Profile icon
lightningrock

love it! is lolcode a joke? because the syntax is rly weird and funny too.

Profile icon
cannonthepom123

@lightningrock
i think so

Profile icon
Reader8765

LOLCODE is a fun language. It was even featured in the newsletter once!

Profile icon
minermaniac447

@Reader8765
Yeah, that's why I did it for my tutorial. Glad you found it fun!

Profile icon
SlendyBendy001

LOLCODE RULES!!!

Profile icon
DabDatBass

LOLCODE is easier to understand than JS, although LOLCODE is basically JS. Still fine and better to work with, lol

Profile icon
mkhoi

I LOVE THE SOCIETY WE LIVE IN!!!
(except those other horrible stuff...)

Profile icon
21Miya

This language scares me, but for some reason I really want to try it now--In fact, this is my first time hearing about it. This is a great tutorial! Upvoted :)

Profile icon
tyxx

good jobbbbbbbbbbb

Profile icon
George-Tsim-Nuj

how do i do graphics with lolcode?

Profile icon
UchihaKagami

IMG_20210809_190249_783

Profile icon
HampusLundborg

hello

Profile icon
TimeDragon

Self-taught in LOLCODE. Nice tutorial though!

Profile icon
Darksexynigga

yes

Profile icon
niamh6

h i

Profile icon
niamh6

n u n u n u n u n u n u n n u n u n u n u n u n u n u n u n u n u n u

Profile icon
niamh6

@niamh6
stop

Profile icon
pbransby21920

i think you explained very well

Profile icon
Flashyyy

Cool

Profile icon
fluffykitty421

i just wish replit could handle lolcode inputs better

Profile icon
JobJobert

Invalid image url

Profile icon
FlaminHotValdez

I HAS A COMPLIMENT ITZ "UR AWSUM"

Profile icon
brooc210

memes...

Profile icon
brooc210

@brooc210
I replied to myself!

Profile icon
brooc210

LoL indeed

Profile icon
MemeManHimself

for some reason this is so hard for me to learn and remember XD

Profile icon
King597

THIS IS DEFINITLY MY NOO FAVRIT LANGUAJ!!!!

Profile icon
[deleted]

ITS DA TWOOF

Profile icon
JORDANSISNEY

I don't know if I will ever actually use LOLCODE sometime in my life ever, but the syntax makes me laugh a lot lol. Thanks for the tutorial! :D

Profile icon
JSer

Super cool! Now I don't have to browser that ugly TutorialsPoint website or watch crappy tutorial videos on YouTube to learn LOLCODE

Profile icon
AhmedKhalifaAhm

DIFFRINT [variable 1] AN BIGGR OF [variable 1] AN [variable 2] BTW variable 1 > variable 2
DIFFRINT [variable 1] AN SMALLR OF [variable 1] AN [variable 2] BTW variable 1 < variable 2
I think it's the other way around:
(a != max(a, b) --> a < b)
(a != min(a, b) --> a > b)