Code Examples

Some program examples of LOLCODE to stress the compiler:

A prime number finder, finds the largest prime up to a certain number:

HAI
I HAS A lnum
I HAS A lprime ITZ -1
VISIBLE "Number to search for largest prime!"
GIMMEH lnum
IM IN YR loop UPPIN YR cnum TILL BOTH SAEM cnum AN lnum
    BOTH SAEM cnum AN 0
    O RLY?
        YA RLY
            cnum R 2
    OIC
    I HAS A flag ITZ FAIL
    IM IN YR iloop UPPIN YR inum TILL BOTH SAEM inum AN CNUM
        BOTH SAEM inum AN 0
        O RLY?
            YA RLY
                inum R 2
        OIC
        BOTH SAEM MOD OF cnum AN inum AN 0
        O RLY?
            YA RLY
                flag R WIN
                inum R cnum
        OIC
    IM OUTTA YR iloop
    NOT flag
    O RLY?
        YA RLY
            lprime R cnum
    OIC
IM OUTTA YR loop
DIFFRINT lprime AN -1
O RLY?
    YA RLY
        VISIBLE SMOOSH "Largest prime is " lprime MKAY
    NO WAI
        VISIBLE "No prime found!"
OIC
KTHXBYE
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License