View Single Post
Old 05-12-2022, 10:46 AM   #10
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,469
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I am implementing the for/range loop.

Syntax:
Code:
for_expr  ::= for_list | for_range
for_list  ::= 'for' identifier 'in' list_expr 
          [ 'separator' separator_expr ] ':' expression_list 'rof'
for_range ::= 'for' variable 'range' [ start_expr 'to' ] stop_expr
          [ 'limit' limit_expr ] ':' expression_list 'rof'
The loop is zero-based -- from start_expr up to but not including stop_expr. Example: "range 0 to 10" counts from zero to nine. This makes loops that reference lists and strings more natural, as in this example that uppercases every other letter in the title.
Code:
program:
	res = '';
	for i range 0 to strlen($title):
	    c = substr($title, i, i+1);
	    res = strcat(res, if mod(i, 2) == 0 then uppercase(c) else c fi)
	rof
If you omit the start_expr then it is set to zero.

The limit specified the maximum number of loop iterations allowed. It is set to 1000 if omitted.
chaley is offline   Reply With Quote