Discussions in support of the LOLCODE.com wiki
You are not logged in.
IM IN YR <label> <operation> YR <variable> [TIL|WILE <expression>] <code block> IM OUTTA YR <label>
I take it that the variable can be used as an index within the loop, but there seems no way to specify a start value.
How about this variant?
IM IN YR <variable> <operation> YR <start epression> [TIL|WILE <expression>] <code block> IM OUTTA YR <variable>
As in:
HOW DUZ I COUNTDOWN YR Start
IM IN YR beat NERFIN YR Start TIL 0
VISIBLE beat "! "!
IM OUTA YR beat
IF U SAY SO
COUNTDOWN 10
10! 9! 8! 7! 6! 5! 4! 3! 2! 1! 0!Last edited by JennyB (2007-07-09 09:59:07)
Offline
Okay, I had a look at the spec.
If you can predeclare the var, then you can give it a starting value.
Here's how it could work in the given spec:
HOW DUZ I COUNTDOWN YR start
I HAS A BEAT ITZ start
IM IN YR BAND NERFIN YR BEAT TIL BOTH SAEM BEAT AN 0
VISIBLE BEAT "! "!
IM OUTTA YR BAND
IF U SAY SOBut we could easily add (and I think it was proposed), something like FROM:
HOW DUZ I COUNTDOWN YR start
IM IN YR BAND NERFIN YR BEAT FROM start TIL BOTH SAEM BEAT AN 0
VISIBLE BEAT "! "!
IM OUTTA YR BAND
IF U SAY SOI think the label allows you to give it flavor. The problem is that the proposed change looks odd when you stick in numbers or other expressions, I think:
HOW DUZ I COUNTDOWN?
IM IN YR COUNT NERFIN YR 10 TIL BOTH SAEM COUNT AN 0
VISIBLE COUNT "! "!
IM OUTTA YR COUNT
IF U SAY SO
or
HOW DUZ I FACTORIZE YR TING?
IM IN YR COUNT UPPIN YR 2 TIL BOTH SAEM COUNT AN BIGR OF COUNT AN SQUARE_ROOT TING
BOTH SAEM 0 AN MOD OF TING AN COUNT
O RLY?
YA RLY, VISIBLE COUNT "! "!
OIC
IM OUTTA YR COUNT
IF U SAY SOIt just doesn't read right. But:
HOW DUZ I FACTORIZE YR TING?
I HAS A COUNT ITZ 2
IM IN YR FACTORIZOR UPPIN YR COUNT TIL BOTH SAEM COUNT AN BIGR OF COUNT AN SQUARE_ROOT TING
BOTH SAEM 0 AN MOD OF TING AN COUNT
O RLY?
YA RLY, VISIBLE COUNT "! "!
OIC
IM OUTTA YR FACTORIZOR
IF U SAY SO
or
IM IN YR FACTORIZOR UPPIN YR COUNT FROM 2 TIL ...
BOTH SAEM COUNT AN BIGR OF COUNT AN SQUARE_ROOT TINGThe label gives it flavor. UPPIN YR 2 just doesn't work so good.
Offline
Personally, I like loops having names. It gives us the possibility of named breaks and continues, too. Naming it after the variable doesn't work so well, IMO.
That said, I'm not hugely attached to that POV.
Offline
Arachnid wrote:
Personally, I like loops having names. It gives us the possibility of named breaks and continues, too. Naming it after the variable doesn't work so well, IMO.
That said, I'm not hugely attached to that POV.
By 'named breaks' you mean 'GTFO loop'or 'GTFO name' to branch to 'OIC name' and perhaps 'AGAEN loop for CONTINUE? Interesting.
I'm opposed to having a label as well as a variable because then you need to think of a name for both even if your counted loop doesn't ever reference the index.
Looking back, I realise I've just re-invented the FOR loop:
FOR var=start TO end [BY step] DO IM IN YR var [UPPIN/NERFIN [YR] start] [TIL end] ... [STEPPIN step] ...
Var is local to the loop and set to the value of start on entry. Start and end are numerical expressions, not boolean, and evaluated only on entry to the loop. If either are missing, it is assumed to be 0.
UPPIN and NERFIN are indicators which direction the loop is meant to go. If there is no STEPPIN in the loop, then code is compiled at the end of the loop to increment var and exit the loop if it now exceeds end if UPPIN, or to nerf it and exit if it is now less if NERFIN. Otherwise, only an unconditional loop is compiled and the exit is handled by STEPPIN, which ups or nerfs var by step and exits if the limit is crossed. The step can vary on each iteration. Positive steps tend towards loop termination whether UPPIN or NERFIN, negative steps delay termination.
STEPPIN can appear anywhere in the loop (there may even be more than one). If the distance between var and end is less than step, then the loop is exited.
HOW DUZ I COUNTDOWN YR number BTW prints from number-1 to 0
IM IN YR COUNT NERFIN YR number
STEPPIN 1 BTW prints nothing if number=0
VISIBLE COUNT "! "!
BTW with no STEPPIN there would be an implicit STEPPIN 1 here
IM OUTTA YR COUNT BTW and the loop would print from number to 0
IF U SAY SO
or
HOW DUZ I FACTORIZE YR TING?
IM IN YR FACTOR UPPIN 2 TIL SQUARE_ROOT TING
BOTH SAEM 0 AN MOD OF TING AN COUNT
O RLY?
YA RLY, VISIBLE FACTOR "! "!
OIC BTW implicit STEPPIN 1 here
IM OUTTA YR FACTOR
IF U SAY SOLast edited by JennyB (2007-07-11 09:18:45)
Offline