Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Flow-control_structures
note: Control Structures

View file

@ -0,0 +1,16 @@
{{Control Structures}}
;Task:
Document common flow-control structures.
One common example of a flow-control structure is the &nbsp; <big><code> goto </code></big> &nbsp; construct.
Note that &nbsp; [[Conditional Structures]] &nbsp; and &nbsp; [[Iteration|Loop Structures]] &nbsp; have their own articles/categories.
;Related tasks:
* &nbsp; [[Conditional Structures]]
* &nbsp; [[Iteration|Loop Structures]]
<br><br>

View file

@ -0,0 +1,12 @@
V n = 10
Int result
L(i) 0 .< n
I (n % 2) == 0
L.continue
I (n % i) == 0
result = i
L.break
L.was_no_break
result = -1
print(No odd factors found)

View file

@ -0,0 +1,2 @@
B TESTPX goto label TESTPX
BR 14 goto to the address found in register 14

View file

@ -0,0 +1,7 @@
LA 15,SINUSX load in reg15 address of function SINUSX
BALR 14,15 call the subroutine SINUX and place address RETPNT in reg14
RETPNT EQU *
SINUSX EQU * subroutine SINUSX
...
BR 14 return to caller

View file

@ -0,0 +1,8 @@
L 4,A Load A in register 4
C 4,B Compare A with B
BH TESTGT Branch on High if A>B then goto TESTGT
BL TESTLT Branch on Low if A<B then goto TESTLT
BE TESTEQ Branch on Equal if A=B then goto TESTEQ
BNH TESTLE Branch on Not High if A<=B then goto TESTLE
BNL TESTGE Branch on Not Low if A>=B then goto TESTGE
BNE TESTNE Branch on Not Equal if A<>B then goto TESTNE

View file

@ -0,0 +1,4 @@
LA 3,8 r3 loop counter
LOOP EQU *
... loop 8 times (r3=8,7,...,2,1)
BCT 3,LOOP r3=r3-1 ; if r3<>0 then loop

View file

@ -0,0 +1,7 @@
* do i=1 to 8 by 2
L 3,1 r3 index and start value 1
LA 4,2 r4 step 2
L 5,8 r5 to value 8
LOOPI EQU *
... loop 4 times (r3=1,3,5,7)
BXLE 3,4,LOOPI r3=r3+r4; if r3<=r5 then loop

View file

@ -0,0 +1,7 @@
* do i=8 to 1 by -2
L 3,1 r3 index and start value 8
LH 4,=H'-2' r4 step -2
L 5,8 r5 to value 1
LOOPI EQU *
... loop 4 times (r3=8,6,4,2)
BXH 3,4,LOOPI r3=r3+r4; if r3>r5 then loop

View file

@ -0,0 +1,2 @@
JMP $8000 ;immediately JuMP to $8000 and begin executing
;instructions there.

View file

@ -0,0 +1,2 @@
JMP ($8000) ;immediately JuMP to the address in memory locations
;$8000 and $8001

View file

@ -0,0 +1 @@
JSR $8000 ;Jump to SubRoutine

View file

@ -0,0 +1 @@
RTS ;ReTurn from Subroutine

View file

@ -0,0 +1,12 @@
(
FOR j TO 1000 DO
FOR i TO j-1 DO
IF random > 0.999 THEN
printf(($"Exited when: i="g(0)", j="g(0)l$,i,j));
done
FI
# etc. #
OD
OD;
done: EMPTY
);

View file

@ -0,0 +1,12 @@
STRING medal = (
[]PROC VOID award = (gold,silver,bronze);
award[ 1 + ENTIER (random*3)];
gold: "Gold" EXIT
silver: "Silver" EXIT
bronze: "Bronze"
);
print(("Medal awarded: ",medal, new line));

View file

@ -0,0 +1,21 @@
STRING final state = (
INT condition;
PROC do something = VOID: condition := 1 + ENTIER (3 * random);
state1:
do something;
CASE condition IN
state 1, state 2
OUT
state n
ESAC
EXIT
state 2:
"State Two"
EXIT
state n:
"State N"
);
print(("Final state: ",final state, new line));

View file

@ -0,0 +1,22 @@
# example from: http://www.xs4all.nl/~jmvdveer/algol.html - GPL #
determine first generation;
WHILE can represent next generation
DO calculate next generation;
print next generation
OD.
determine first generation:
INT previous := 1, current := 3.
can represent next generation:
current <= max int - previous.
calculate next generation:
INT new = current + previous;
previous := current;
current := new.
print next generation:
printf (($lz","3z","3z","2z-d$, current,
$xz","3z","3z","2z-d$, previous,
$xd.n(real width - 1)d$, current / previous)).

View file

@ -0,0 +1,18 @@
begin
integer i;
integer procedure getNumber ;
begin
integer n;
write( "n> " );
read( i );
if i< 0 then goto negativeNumber;
i
end getNumber ;
i := getNumber;
write( "positive or zero" );
go to endProgram;
negativeNumber:
writeon( "negative" );
endProgram:
end.

View file

@ -0,0 +1,12 @@
SWI n ;software system call
B label ;Branch. Just "B" is a branch always, but any condition code can be added for a conditional branch.
;In fact, almost any instruction can be made conditional to avoid branching.
BL label ;Branch and Link. This is the equivalent of the CALL command on the x86 or Z80.
;The program counter is copied to the link register, then the operand of this command becomes the new program counter.
BX Rn ;Branch and Exchange. The operand is a register. The program counter is swapped with the register specified.
;BX LR is commonly used to return from a subroutine.
addeq R0,R0,#1 ;almost any instruction can be made conditional. If the flag state doesn't match the condition code, the instruction
;has no effect on registers or memory.

View file

@ -0,0 +1,5 @@
$ awk 'BEGIN{for(i=1;;i++){if(i%2)continue; if(i>=10)break; print i}}'
2
4
6
8

View file

@ -0,0 +1,3 @@
<<Top>>
Put_Line("Hello, World");
goto Top;

View file

@ -0,0 +1,8 @@
Outer:
loop
-- do something
loop
-- do something else
exit Outer; -- exits both the inner and outer loops
end loop;
end loop;

View file

@ -0,0 +1,7 @@
select
delay 10.0;
Put_Line ("Cannot finish this in 10s");
then abort
-- do some lengthy calculation
...
end select;

View file

@ -0,0 +1,14 @@
MsgBox, calling Label1
Gosub, Label1
MsgBox, Label1 subroutine finished
Goto Label2
MsgBox, calling Label2 ; this part is never reached
Return
Label1:
MsgBox, Label1
Return
Label2:
MsgBox, Label2 will not return to calling routine
Return

View file

@ -0,0 +1,12 @@
gosub subrutina
bucle:
print "Bucle infinito"
goto bucle
subrutina:
print "En subrutina"
pause 10
return
end

View file

@ -0,0 +1,11 @@
GOSUB subroutine
(loop)
PRINT "Infinite loop"
GOTO loop
END
(subroutine)
PRINT "In subroutine"
WAIT 100
RETURN

View file

@ -0,0 +1,6 @@
( LOOP
= out$"Hi again!"
& !LOOP
)
& out$Hi!
& !LOOP

View file

@ -0,0 +1,8 @@
#include <iostream>
int main()
{
LOOP:
std::cout << "Hello, World!\n";
goto LOOP;
}

View file

@ -0,0 +1,71 @@
#include <iostream>
#include <ostream>
void foo()
{
std::cout << "Going to throw an exception.\n";
throw 7; // almost any object can be thrown, including ints
std::throw << "This output will never execute.\n";
}
void bar()
{
std::cout << "Going to call foo().\n";
foo();
std::cout << "This will be skipped by the exception coming from foo.\n";
}
void baz()
{
try // everything thrown from inside the following code block
{ // will be covered by the following catch clauses
std::cout << "Going to call bar().\n";
bar();
std::cout << "This will be skipped by the exception coming from foo.\n";
}
catch(...) // a simple catch-all, but doesn't give access to the thrown exception
{
std::cout << "An exception occured. I'll just throw it on.\n";
throw; // without an argument, the caught exception is re-thrown
}
std::cout << "This will not be executed due to the re-throw in the catch block\n";
}
void foobar()
{
try
{
baz();
}
catch(char const* s)
{
std::cout << "If foo had thrown a char const*, this code would be executed.\n";
std::cout << "In that case, the thrown char const* would read " << s << ".\n";
}
catch(int i)
{
std::cout << "Caught an int, with value " << i << " (should be 7).\n";
std::cout << "Not rethrowing the int.\n";
}
catch(...)
{
std::cout << "This catch-all doesn't get invoked because the catch(int) above\n"
<< "already took care of the exception (even if it had rethrown the\n"
<< "exception, this catch-all would not be invoked, because it's\n"
<< "only invoked for exceptions coming from the try block.\n";
}
std::cout << "This will be executed, since the exception was handled above, and not rethrown.\n";
}
int main()
{
try
{
foobar();
}
catch(...)
{
std::cout << "The main function never sees the exception, because it's completely handled\n"
<< "inside foobar(). Thus this catch-all block never gets invoked.\n";
}
}

View file

@ -0,0 +1,3 @@
int GetNumber() {
return 5;
}

View file

@ -0,0 +1,10 @@
try {
if (someCondition) {
throw new Exception();
}
} catch (Exception ex) {
LogException(ex);
throw;
} finally {
cleanUp();
}

View file

@ -0,0 +1,13 @@
public static void Main() {
foreach (int n in Numbers(i => i >= 2) {
Console.WriteLine("Got " + n);
}
}
IEnumerable<int> Numbers(Func<int, bool> predicate) {
for (int i = 0; ; i++) {
if (predicate(i)) yield break;
Console.WriteLine("Yielding " + i);
yield return i;
}
}

View file

@ -0,0 +1,5 @@
async Task DoStuffAsync() {
DoSomething();
await someOtherTask;//returns control to caller if someOtherTask is not yet finished.
DoSomethingElse();
}

View file

@ -0,0 +1,7 @@
while (conditionA) {
for (int i = 0; i < 10; i++) {
if (conditionB) goto NextSection;
DoSomething(i);
}
}
NextSection: DoOtherStuff();

View file

@ -0,0 +1,13 @@
int main()
{
int i,j;
for (j=1; j<1000; j++) {
for (i=0; i<j, i++) {
if (exit_early())
goto out;
/* etc. */
}
}
out:
return 0;
}

View file

@ -0,0 +1,8 @@
PROGRAM-ID. Go-To-Example.
PROCEDURE DIVISION.
Foo.
DISPLAY "Just a reminder: GO TOs are evil."
GO TO Foo
.

View file

@ -0,0 +1,4 @@
GO TO First-Thing Second-Thing Third-Thing
DEPENDING ON Thing-To-Do
* *> Handle invalid thing...

View file

@ -0,0 +1,13 @@
EVALUATE Thing-To-Do
WHEN 1
* *> Do first thing...
WHEN 2
* *> Do second thing...
WHEN 3
* *> Do third thing...
WHEN OTHER
* *> Handle invalid thing...
END-EVALUATE

View file

@ -0,0 +1,38 @@
identification division.
program-id. altering.
procedure division.
main section.
*> And now for some altering.
contrived.
ALTER story TO PROCEED TO beginning
GO TO story
.
*> Jump to a part of the story
story.
GO.
.
*> the first part
beginning.
ALTER story TO PROCEED to middle
DISPLAY "This is the start of a changing story"
GO TO story
.
*> the middle bit
middle.
ALTER story TO PROCEED to ending
DISPLAY "The story progresses"
GO TO story
.
*> the climatic finish
ending.
DISPLAY "The story ends, happily ever after"
.
*> fall through to the exit
exit program.

View file

@ -0,0 +1,23 @@
PROGRAM-ID. Perform-Example.
PROCEDURE DIVISION.
Main.
PERFORM Moo
PERFORM Display-Stuff
PERFORM Boo THRU Moo
GOBACK
.
Display-Stuff SECTION.
Foo.
DISPLAY "Foo " WITH NO ADVANCING
.
Boo.
DISPLAY "Boo " WITH NO ADVANCING
.
Moo.
DISPLAY "Moo"
.

View file

@ -0,0 +1,5 @@
myprocedure
END // End of main program
PROC myprocedure
PRINT "Hello, this is a procedure"
ENDPROC myprocedure

View file

@ -0,0 +1,5 @@
LOOP
PRINT "I'm in a loop!"
EXIT
ENDLOOP
PRINT "But i somehow got out of it."

View file

@ -0,0 +1,6 @@
PRINT "I'm in a loop!"
LOOP
INPUT "Do you want to exit?":answer$
EXIT WHEN answer$="y"
ENDLOOP
PRINT "You got out of it."

View file

@ -0,0 +1,6 @@
PRINT "Hello world"
GOTO label
PRINT "This line will never be output"
label:
PRINT "This program will end thanks to the evil GOTO statement"
END

View file

@ -0,0 +1,7 @@
import std.stdio;
void main() {
label1:
writeln("I'm in your infinite loop.");
goto label1;
}

View file

@ -0,0 +1,22 @@
import std.stdio;
class DerivedException : Exception {
this(string msg) { super(msg); }
}
void main(string[] args) {
try {
if (args[1] == "throw")
throw new Exception("message");
} catch (DerivedException ex) {
// We never threw a DerivedException, so this
// block is never called.
writefln("caught derived exception %s", ex);
} catch (Exception ex) {
writefln("caught exception: %s", ex);
} catch (Throwable ex) {
writefln("caught throwable: %s", ex);
} finally {
writeln("finished (exception or none).");
}
}

View file

@ -0,0 +1,13 @@
import std.stdio;
void main(string[] args) {
scope(exit)
writeln("Gone");
if (args[1] == "throw")
throw new Exception("message");
scope(exit)
writeln("Gone, but we passed the first" ~
" chance to throw an exception.");
}

View file

@ -0,0 +1,13 @@
: checked-array
CREATE ( size -- ) DUP , CELLS ALLOT
DOES> ( i -- a+i )
2DUP @ 0 SWAP WITHIN IF
SWAP 1+ CELLS +
ELSE
1 THROW
THEN ;
8 checked-array myarray
: safe-access ( i -- a[i] )
['] myarray CATCH 1 = IF ." Out of bounds!" 0 THEN ;

View file

@ -0,0 +1,12 @@
...
ASSIGN 1101 to WHENCE !Remember my return point.
GO TO 1000 !Dive into a "subroutine"
1101 CONTINUE !Resume.
...
ASSIGN 1102 to WHENCE !Prepare for another invocation.
GO TO 1000 !Like GOSUB in BASIC.
1102 CONTINUE !Carry on.
...
Common code, far away.
1000 do something !This has all the context available.
GO TO WHENCE !Return whence I came.

View file

@ -0,0 +1,4 @@
ASSIGN 2000 TO WHENCE !Deviant "return" from 1000 to invoke 2000.
ASSIGN 1103 TO THENCE !Desired return from 2000.
GO TO 1000
1103 CONTINUE

View file

@ -0,0 +1,6 @@
SUBROUTINE FRED(X,*,*) !With placeholders for unusual parameters.
...
RETURN !Normal return from FRED.
...
RETURN 2 !Return to the second label.
END

View file

@ -0,0 +1,9 @@
XX:DO WHILE(condition)
statements...
NN:DO I = 1,N
statements...
IF (...) EXIT XX
IF (...) CYCLE NN
statements...
END DO NN
END DO XX

View file

@ -0,0 +1,14 @@
'$lang: "qb"
Gosub subrutina
bucle:
Print "Bucle infinito"
Goto bucle
End
subrutina:
Print "En subrutina"
Sleep 100
Return
Sleep

View file

@ -0,0 +1,7 @@
10 LET a=1
20 IF a=2 THEN PRINT "This is a conditional statement"
30 IF a=1 THEN GOTO 50: REM a conditional jump
40 PRINT "This statement will be skipped"
50 PRINT ("Hello" AND (1=2)): REM This does not print
100 PRINT "Endless loop"
110 GOTO 100:REM an unconditional jump

View file

@ -0,0 +1,11 @@
Public Sub Main()
Dim siCount As Short
LOOPIT:
Print siCount;;
Inc siCount
If siCount > 100 Then Quit
Goto LoopIt
End

View file

@ -0,0 +1,4 @@
func main() {
inf:
goto inf
}

View file

@ -0,0 +1,18 @@
import "os"
func processFile() {
f, err := os.Open("file")
if err != nil {
// (probably do something with the error)
return // no need to close file, it didn't open
}
defer f.Close() // file is open. no matter what, close it on return
var lucky bool
// some processing
if (lucky) {
// f.Close() will get called here
return
}
// more processing
// f.Close() will get called here too
}

View file

@ -0,0 +1,16 @@
package main
import "fmt"
func printOnes() {
for {
fmt.Println("1")
}
}
func main() {
go printOnes()
for {
fmt.Println("0")
}
}

View file

@ -0,0 +1,8 @@
func answer(phone1, phone2 chan int) {
select {
case <-phone1:
// talk on phone one
case <-phone2:
// talk on phone two
}
}

View file

@ -0,0 +1,12 @@
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Exit
main = do
runExitTMaybe $ do
forM_ [1..5] $ \x -> do
forM_ [1..5] $ \y -> do
lift $ print (x, y)
when (x == 3 && y == 2) $
exitWith ()
putStrLn "Done."

View file

@ -0,0 +1,17 @@
1 GOTO 2 ! branch to label
2 READ(FIle=name, IOStat=ios, ERror=3) something ! on error branch to label 3
3 ALARM(delay, n) ! n=2...9 simulate F2 to F9 keys: call asynchronously "Alarm"-SUBROUTINES F2...F9 with a delay
4 ALARM( 1 ) ! lets HicEst wait at this statement for any keyboard or mouse event
5 SYSTEM(WAIT=1000) ! msec
6 XEQ('CALL my_subroutine', *7) ! executes command string, on error branch to label 7
7 y = EXP(1E100, *8) ! on error branch to label 8
8 y = LOG( 0 , *9) ! on error branch to label 9
9 ALARM( 999 ) ! quit HicEst immediately

View file

@ -0,0 +1,3 @@
test:
..some code here
goto, test

View file

@ -0,0 +1 @@
on_error, test

View file

@ -0,0 +1 @@
on_ioerror, test

View file

@ -0,0 +1 @@
break

View file

@ -0,0 +1 @@
continue

View file

@ -0,0 +1,9 @@
if x := every i := 1 to *container do { # * is the 'length' operator
if container[i] ~== y then
write("item ", i, " is not interesting")
else
break a
} then
write("found item ", x)
else
write("did not find an item")

View file

@ -0,0 +1 @@
break break next

View file

@ -0,0 +1 @@
x := ftn()

View file

@ -0,0 +1,8 @@
&error := 1
mayErrorOut()
if &error == 1 then
&error := 0 # clear the trap
else {
# deal with the fault
handleError(&errornumber, &errortext, &errorvalue) # keyword values containing facts about the failure
}

View file

@ -0,0 +1 @@
runerr(errnumber, errorvalue) # choose an error number and supply the offending value

View file

@ -0,0 +1,2 @@
2 * 1 2 3
2 4 6

View file

@ -0,0 +1,33 @@
switch (xx) {
case 1:
case 2:
/* 1 & 2 both come here... */
...
break;
case 4:
/* 4 comes here... */
...
break;
case 5:
/* 5 comes here... */
...
break;
default:
/* everything else */
break;
}
for (int i = 0; i < 10; ++i) {
...
if (some_condition) { break; }
...
}
_Time_: do {
for (int i = 0; i < 10; ++i) {
...
if (some_condition) { break _Time_; /* terminate the do-while loop */}
...
}
...
} while (thisCondition);

View file

@ -0,0 +1,25 @@
while (condition) {
...
if (someCondition) { continue; /* skip to beginning of this loop */ }
...
}
top: for (int 1 = 0; i < 10; ++i) {
...
middle: for (int j = 0; j < 10; ++j) {
...
bottom: for (int k = 0; k < 10; ++k) {
...
if (top_condition) { continue top; /* restart outer loop */ }
...
if (middle_condition) { continue middle; /* restart middle loop */ }
...
if (bottom_condition) { continue bottom; /* restart bottom loop */ }
...
if (bottom_condition) { continue; /* this will also restart bottom loop */ }
...
}
...
}
....
}

View file

@ -0,0 +1,2 @@
# Emit at most one item from the stream generated by g:
def first(g): label $out | g | ., break $out;

View file

@ -0,0 +1,7 @@
function example()
println("Hello ")
@goto world
println("Never printed")
@label world
println("world")
end

View file

@ -0,0 +1,14 @@
// version 1.0.6
fun main(args: Array<String>) {
for (i in 0 .. 2) {
for (j in 0 .. 2) {
if (i + j == 2) continue
if (i + j == 3) break
println(i + j)
}
}
println()
if (args.isNotEmpty()) throw IllegalArgumentException("No command line arguments should be supplied")
println("Goodbye!") // won't be executed
}

View file

@ -0,0 +1,5 @@
i = 0
while true do
i = i + 1
if i > 10 then break end
end

View file

@ -0,0 +1,9 @@
function func1 ()
return func2()
end
function func2 ()
return func1()
end
func1()

View file

@ -0,0 +1,38 @@
Module Inner {
long x=random(1, 2)
on x goto 90, 100
090 print "can print here if is "+x // if x=1
100 Print "ok"
gosub 500
alfa: // no statement here only comments because : is also statement separator
print "ok too"
integer c
Every 100 { // every 100 miliseconds this block executed
c++
gosub printc
if c>9 then 200
}
print "no print here"
200 Gosub exitUsingGoto
Every 100 { // every 100 miliseconds this block executed
c++
gosub printc
if c>19 then exit
}
gosub 500
try ok {
on x gosub 400, 1234
}
if ok else print error$ // sub not found (if x=2)
goto 1234 ' not exist so this is an exit from module
400 print "can print here if is "+x // if x=1
end
printc:
Print c
return
500 Print "exit from block using exit" : return
exitUsingGoto:
Print "exit from block using goto"
return
}
Inner

View file

@ -0,0 +1,27 @@
module outer {
static m as long=100 // if m not exist created
module count (&a(), b) {
long c=1
do
if b(c) then exit
call a(c)
c++
always
}
long z, i=100
// function k used as call back function, through lazy$()
function k {
read new i
print i // print 1 and 2
z+=i
m++
}
count lazy$(&k()), (lambda (i)->i>=3)
print z=3, i=100, m
}
clear // clear variables (and static variables) from this point
outer // m is 102
outer // m is 104
outer // m is 106

View file

@ -0,0 +1,29 @@
Module checkSelect {
long m, i, k
for k=1 to 10
m=10
i=random(5, 10)
select case i
case <6
print "less than 6"
case 6
{
m++: break // break case block, and continue to next block
}
case 7
{
m++: break
}
case 8
{
m++: continue // exit after end select
}
case 9
print "is 9"
case else
print "more than 9"
end select
print m, i
next
}
checkSelect

View file

@ -0,0 +1,5 @@
try
% do some stuff
catch
% in case of error, continue here
end

View file

@ -0,0 +1 @@
GOTO LABEL^ROUTINE

View file

@ -0,0 +1 @@
GOTO THERE

View file

@ -0,0 +1,2 @@
Read "Do you really wish to halt (Y/N)?",Q#1
IF Q="Y"!Q="y" HALT

View file

@ -0,0 +1 @@
JOB LABEL^ROUTINE

View file

@ -0,0 +1 @@
JOB THERE

View file

@ -0,0 +1 @@
JOB LABEL^ROUTINE

View file

@ -0,0 +1,2 @@
FOR I=1:1:1 QUIT:NoLoop DO YesLoop
QUIT Returnvalue

View file

@ -0,0 +1,4 @@
SET A="SET %=$INCREMENT(I)"
SET I=0
XECUTE A
WRITE I

View file

@ -0,0 +1,8 @@
/* goto */
block(..., label, ..., go(label), ...);
/* throw, which is like trapping errors, and can do non-local jumps to return a value */
catch(..., throw(value), ...);
/* error trapping */
errcatch(..., error("Bad luck!"), ...);

View file

@ -0,0 +1,4 @@
loop xx = 1 to 10
if xx = 1 then leave -- loop terminated by leave
say 'unreachable'
end

View file

@ -0,0 +1,43 @@
loop xx = 1 to 10 -- xx is the control variable
...
loop yy = 1 to 10 -- yy is the control variable
...
if yy = 3 then leave xx -- xx loop terminated by leave
if yy = 4 then leave yy -- yy loop terminated by leave
...
end
...
end xx
loop label xlabel xx = 1 to 10 -- xx is still the control variable but LABEL takes precidence
...
loop yy = 1 to 10 -- yy is the control variable
...
if yy = 3 then leave xlabel -- xx loop terminated by leave
...
end yy
...
end xlabel
do label FINIS
say 'in do block'
if (1 == 1) then leave FINIS
say 'unreachable'
signal Exception("Will never happen")
catch ex = Exception
ex.printStackTrace()
finally
say 'out of do block'
end FINIS
loop vv over ['A', 'B']
select label selecting case vv
when 'A' then do; say 'A selected'; say '...'; end
when 'B' then do;
say 'B selected';
if (1 == 1) then leave selecting;
say '...';
end
otherwise do; say 'nl selection'; say '...'; end
end selecting
end vv

View file

@ -0,0 +1,9 @@
loop fff = 0 to 9
...
loop xx = 1 to 3
...
if fff > 2 then iterate fff
...
end
...
end fff

View file

@ -0,0 +1,5 @@
block outer:
for i in 0..1000:
for j in 0..1000:
if i + j == 3:
break outer

View file

@ -0,0 +1,7 @@
var f = open "input.txt"
try:
var s = readLine f
except IOError:
echo "An error occurred!"
finally:
close f

View file

@ -0,0 +1,10 @@
exception Found of int
let () =
(* search the first number in a list greater than 50 *)
try
let nums = [36; 23; 44; 51; 28; 63; 17] in
List.iter (fun v -> if v > 50 then raise(Found v)) nums;
print_endline "nothing found"
with Found res ->
Printf.printf "found %d\n" res

View file

@ -0,0 +1 @@
break

View file

@ -0,0 +1 @@
continue

Some files were not shown because too many files have changed in this diff Show more