Possible if-then-else branching.
HAI
I HAS A VAR
VAR IZ 10 O RLY?
YA RLY
VISIBLE "YOU HAVE 10"
NO WAI
VISIBLE "YOU DON'T HAVE 10"
KTHXBYE
KTHXBYE
Alternatively, OH RLY? might serve as a rescue condition for error checking.
O RLY, YA RLY and NO WAI would be good branch operators, but the “VAR IZ” would conflict what what appears to be being used as an assignment. I propose elsewhere to use “LOL <var> R <val>” which wouldn't conflict, and it would free up “IZ ” for use elsewhere (such as in conditionals)… so in that vein, I propose (this is in lieu of the current ”:(” for else condition):
IZ <condition> <statements> O RLY IZ <condition> BTW This is an else-if <statments> NO WAI BTW This is the else <statements> KTHX
Just my thought. I really do think IZ should be used for conditionals though, and not assignment.
— Kyle, 2007/05/29 04:53
Could O RLY, YA RLY, and NO WAI be used in place of TRUE / FALSE? Results could then result in either *RLY (O RLY or YA RLY) for TRUE or NO WAI for FALSE.
— shox, 2007/05/29 14:20
O RLY is a question, YA RLY and NO WAI are statements. So it should be restricted to YA RLY = TRUE and NO WAI = FALSE.
— z7q2, 2007/05/29 14:42
my thoughts exactly. Take a look at LITTLE-NUMBER, which I think points to where we were heading with this.
Thanks for all the input, all! — Adam, 2007/05/29 15:12
I like the syntax in LITTLE-NUMBER. But, what about 'else if'? Too many else-if's with a YA RLY/NO WAI syntax causes multiple indentions and KTHXs.
What about something like:
HAI
CAN HAS STDIO?
I HAS A NUMBAR
GIMMEH NUMBAR
IZ VAR BIGGER THAN 10 O RLY?
YA RLY
VISIBLE "BIG NUMBER!"
MEBBE IZ VAR LESSER THAN 10 O RLY?
YA RLY
VISIBLE "LITTLE NUMBER!"
NO WAI
VISIBLE "MUST BE 10!"
KTHX
KTHXBYE
So, MEBBE IZ acts like an else-if. — Risser, 2007/05/29 16:48
I love MEBBE, it makes perfect sense! :p Not sure if O RLY at the end makes sense grammatically. Oh really is a question after a statement, not a question after a question. So something like
O IZ RLY VAR BIGGER THAN 10? YA RLY BTW SOMETHING NO WAY BTW SOMETHING ELSE KTHX
would make more sense.
— Marius, 2007/05/29 17:00
+1 for MEBBE…I think “O RLY” should be the equivalent to “if”, and therefore should lead the block; this would still fit grammatically. Also, how about SRSLY to close the block? Can't quite decide the nicest way to handle the formatting though…
O RLY IZ var BIGGER THAN 10?
YA RLY
BTW var > 10
MEBBE IZ var LESS THAN 10?
YA RLY
BTW var < 10
NO WAI
BTW var = 10
SRSLY
+1 for SRSLY…, and for O RLY at the beginning. Although, O RLY IZ is really the whole “if”, I think.
I am seeing that YA RLY is totally redundant. And, in addition, it implies that you could do a NO WAI before a MEBBE, which doesn't make sense.
For example, if you could do:
O RLY IZ var BIGGER THAN 10?
YA RLY
BTW var > 10
MEBBE IZ var SMALLER THAN 10?
YA RLY
BTW var < 10
NO WAI
BTW var = 10
SRSLY
the grammar seems to support:
O RLY IZ var BIGGER THAN 10?
NO WAI
BTW what does this even mean, if MEBBE exists?
MEBBE IZ var SMALLER THAN 10?
YA RLY
BTW var < 10
NO WAI
BTW var = 10
SRSLY
But that doesn't really work. I'm for hosing YA RLY. We could keep NO WAI, but there might be something better. Maybe WHATEVER? The finally code might look like this:
O RLY IZ var BIGGER THAN 10?
BTW var > 10
MEBBE IZ var SMALLER THAN 10?
BTW var < 10
WHATEVER
BTW var = 10
SRSLY
— Peter Risser, 2007/05/29 17:51
yeah, i see what you did there (heh, someone needs to think of a way to use that phrase). we could use YA-RLY and NO-WAI as generic macros for true/false, although it's rather awkward:
I HAS A boolvar BTW some code here establishing a value for boolvar O RLY IZ boolvar EQUAL YA-RLY BTW boolvar is true WHATEVER BTW boolvar is false, or NO-WAI SRSLY
meh…not particularly happy with that though. — ILikePi, 2007/05/29 17:57
I've been thinking AMIRITE might be more appropriate for 'if' statements, instead:
var BIGGER THAN 10 AMIRITE?
YARITE
BTW var > 10
MEBBE IZ var SMALLER THAN 10?
YARITE
BTW var < 10
NOU
BTW var = 10
SRSLY
…well, the SRSLY would maybe need to change, but you get the idea.
— backwards, 2007/05/30 17:06
Surely one level if..else..endif statements are more than enough for LOLCATS? Having if..else.. else.. else.. would confuse their poor kitteh ears. So in that sense, O RLY.. MEBBE.. SRSLY or simply O RLY.. SRSLY, makes good sense. Yes, that would mean inevitably lots of nested if..else..endif and yes that isn't pretty, but are we going for beauty in code or 1337 code?
O RLY boolvar SAMEZ AS YA RLY BTW this is true MEBBE BTW this is false SRSLY
— shox, 2007/05/30 18:16 BST
What if a comparison expression, alone, acted as an assertion:
KITTENZ IS BIGGUR THAN 10
If KITTENZ were not bigger than 10, an exception would be thrown (O NOES!). But if such an expression were immediately followed by O RLY? then it would be treated as the predicate for if-then-else. Then it reads cleanly:
KITTENZ IS BIGGUR THAN 10
O RLY?
YA RLY
...
NO WAI
...
KTHX
— Geordan Rosario, 2007/05/30 20:51
Geordan, <name> IS <value> sets the value to the name. — Marius, 2007/05/30 20:59
I'd like to suggest dropping the “O” From “O RLY?” as a way to avoid the (psuedo-)english grammatical problem.
MYVAR IZ 10 RLY?
This statement then becomes a real question; almost every time. It should also allow a compiler to then make “RLY” & “WAI” pointers to an internal boolean. Where “RLY” & “WAI” are the same, with given internal operators “YA” & “NO”.
I could be very wrong ;?)
MrKane - [30/05/07]
In order to preserve “O RLY” in its entirety, and its normal usage as response to a statement, as well as keeping the if statement to a single line, how about:
I HAS A var ITZ 10 var IZ 10! O RLY? LOL "ITZ 10" MEBBE var iz 20 LOL "ITZ 20" NO WAI LOL "ITZ" var KTHX
That being said, the problem with using “O RLY” for an IF statement is that the nicely fitting response “YA RLY” is either not used, or used unecessarily just for the sake of it being there.
I would prefer to use AMIRITE as someone had suggested, and save O RLY..YA RLY for a place where it's more fitting. Syntactically that just means we replace one with the other:
I HAS A var ITZ 10 var IZ 10 AMIRITE LOL "ITZ 10" MEBBE var IZ 20 LOL "ITZ 20" NO WAI LOL "ITZ" var KTHX
- – xrestassuredx, 2007/05/30 21:02
I agree that the we should try to maintain O RLY? as a question, so this is a variation on an the above examples that I think keep things clean. All expressions after the ? are evaluated.
O RLY? kittenz BIGGER THAN 10
YA RLY
...
MEBBE kittenz BIGGER THAN 5
...
NO WAI
...
KTHX
The “foo. O RLY? YA RLY. NO WAI!” is an assertion, questioning, confirmation, denial construct; it follows that something similar should be used for the code.
The comment above almost looks like a switch statement, except the logic is limited to three parts: is, isn't, don't know.
Is this scope for fuzzy logic in lolcode? Surely not!
— Al, 2007/05/31
Al,
BTW LOLCODE : //C
IZ var BIGGER THAN 1? : if(var>1)
YARLY : {
VISIBLE "large" : printf("large");
MEBBEIZ var EQUALZ 0? : }else if(var == 0){
VISIBLE "medium" : printf("medium");
NOWAI : }else{
VISIBLE "small" : printf("small");
KTHX : }
I like AMIRITE. However, doesn't MEBBE sound like an 'if' in and of itself? How about:
I HAS A VARRRRR MAH VARRRRR IZ 10 CHEEZEBURGERS BTW cheezeburgers could denote integer or be just decorative MEBBE VARRRRR IZ 3? BTW do something (no need for a 'then') NO MEBBE VARRRRR IZ 4? BTW do something else NO WAI BTW else O RLY? BTW that was the 'end if'
— Garoo, 2007/05/31
Why not keep the old(er) setup and use YARLY to differntiate between swtich and if/ifelse?
I HAS A LOLRUS
MAH LOLRUZ IZ 10 YEAR
ORLY IZ LOLRUS LESSUR THAN 20?
YARLY
LOL "LITTLE LOLRUS, LOL!"
NOWAI
LOL "BIGGEH LOLRUS!"
SRSLY
GIMMEH LOLRUS
ORLY LOLRUS IZ...
MEBBE 9?
LOL "LOLRUS 9!@!"
NAH
MEEBE 10?
LOL "OKAI, 10 BETTER"
NAH
MEBBE 16?
LOL "LOLRUS HAZ PARTEH!"
NAH
NOWAI
LOL "LOLRUS IZ DIFFRNT"
NAH
KTHX
— Zxaos, 2007/06/14