@EriktheOutgolfer Let's do that then. Should be fairly straight-forward.
Dyalog APL (and most modern APL implementations) support a fairly broad set of control structures. These use keywords (not system functions) and to avoid reserved words, they all begin with a colon, e.g. :If
As you may know, colons are also used in dfns' guards, but no colon-keywords are allowed in dfns, so there's no ambiguity.
Colons may also indicate labels in tradfns, but since keywords generally must be the first word in a statement, and labels must be the first thing on a line, there is again no conflict. Labels have trailing colon, keywords have leading colon. Thus label::If is valid and unambiguous.
Without further ado: :If
If you've used other structured programming languages, you'll find :If very familiar.
And you can add more conditions later with :ElseIf:
[1] :If WINEAGE<5
[2] 'Too young to drink'
[5] :ElseIf WINEAGE<10
[6] 'Just Right'
[7] :ElseIf WINEAGE<15
[8] 'A bit past its prime'
[9] :Else
[10] 'Definitely over the hill'
[11] :EndIf
You can also go more exotic by adding multiple conditions with :AndIf or :OrIf. :AndIfs will only execute if all previous conditions were true, and :OrIfs will only execute if all previous conditions were false.
Maybe here I should mention that for the purposes of control structures with conditions, only simple (non-nested) singleton Boolean (0 or 1) arrays are valid.
If it isn't that wine, but the year is 1962 then you'll only get 'Really?' and 'The greatest?'
@EriktheOutgolfer Well, we can't see what comes below, but if it is just :EndIf, then nothing happens.
@EriktheOutgolfer Meaning, 'Nice' will be skipped because the first condition was false.
Btw, APL control structures are case insensitive, and (for golfing only!) you may omit what is being :Ended, i.e. you can use :End instead of :EndIf and :EndFor etc.
So with :In the variables iterated through the values together, while :InEach had each (!) variable iterate through its own value list.
Btw, in the true spirit of array programming, the values array may have any rank. So you can iterate through a matrix. It will be processed in ravel order.
To not have any condition at the end, you use :EndWhile and EndRepeat.
To have a condition at the end, use :Until (but notice that this is in the negative!)
Just like with :If you can add :AndIf or :OrIf after :While and :Until (although I would advise you not to do that for :Until as it quickly becomes confusing):
[1] :While 100>i
[2] :AndIf 100>j
[3] i j←foo i j
[4] :Until 100<i+j
[5] :OrIf i<0
[6] :OrIf j<0
in the IDE if you don't use )ed to edit the function you prefix every line by its number and then you press enter and that line of the function is modified
If you put statements between :Select and the first case, they will be skipped.
Btw, if for some reason you don't like right-arrows, you can use :GoTo instead. I've no idea why we need both.
A really neat structure is the :Trap. After :Trap you can write one or more error/exception numbers (remember those from Lesson 13?). You can of course use 0 for all errors and 1000 for all exceptions.
If you just want to trap an error and continue, just close the trap structure with :EndTrap. Otherwise you can add case statements identical to those of :Select and APL will jump to the relevant handling block for that particular error:
@betseg I did overhear chatter about :Finally. The idea is that it is guaranteed to be executed even if the block is left early. A bit similar to a destructor in OO.
@EriktheOutgolfer What does that do? (different from just printing unindented and omitting else)
@EriktheOutgolfer Ah, I see. It is like the opposite of Finally. Both run after the block terminates, but Else only if actually finished while FInally no-matter-what.