RosettaCodeData/Task/Repeat/ALGOL-68/repeat.alg

24 lines
863 B
Text
Raw Permalink Normal View History

2024-11-04 20:28:54 -08:00
BEGIN
# operator that executes a procedure the specified number of times #
OP REPEAT = ( INT count, PROC VOID routine )VOID: TO count DO routine OD;
2023-07-01 11:58:00 -04:00
2024-11-04 20:28:54 -08:00
# make REPEAT a low priority operater #
PRIO REPEAT = 1;
2023-07-01 11:58:00 -04:00
2024-11-04 20:28:54 -08:00
# can also create variant that passes the iteration count as a parameter #
OP REPEAT = ( INT count, PROC( INT )VOID routine )VOID:
FOR iteration TO count DO routine( iteration ) OD;
2023-07-01 11:58:00 -04:00
# PROC to test the REPEAT operator with #
PROC say something = VOID: print( ( "something", newline ) );
3 REPEAT say something;
# PROC to test the variant #
2024-11-04 20:28:54 -08:00
PROC show squares = ( INT n )VOID:
print( ( whole( n, 0 ), " ", whole( n * n, 0 ), newline ) );
2023-07-01 11:58:00 -04:00
3 REPEAT show squares
2024-11-04 20:28:54 -08:00
END