Loops/Wrong ranges: Difference between revisions

 
(One intermediate revision by one other user not shown)
Line 1,961:
 
{{trans|Python}}
<syntaxhighlight lang="langur">val .data = qs:block END
val data = qs:block END
start stop increment comment
-2 2 1 Normal
Line 1,974 ⟶ 1,975:
END
 
# Process data string into table.
var .table = submatches(RE/([^ ]+) +([^ ]+) +([^ ]+) +(.+)\n?/, .data)
# We could have just started with a list of lists, of course.
var .table = submatches(RE/([^ ]+) +([^ ]+) +([^ ]+) +(.+)\n?/, .data)
 
for .i in 2..len(.table) {
val .f = fn .x: number .x
.table[.i] = map ([.fnumber, .fnumber, .fnumber, _], .table[.i])
for .i in 2..len(.table) {
.table[.i] = map [.f, .f, .f, _], .table[.i]
}
 
for .test in rest(.table) {
val .start, .stop, .inc, .comment = .test
{
val .seriess = series(.start .. .stop, .inc)
catch {
writeln "{{.comment}}\nERROR: {{_err["'msg"]:L200(...)}}\n"
} else {
writeln "{{.comment}}\nresult: {{.seriess}}\n"
}
}
Line 2,170 ⟶ 2,172:
( 2, 2, 0): not allowed.
( 0, 0, 0): not allowed.</pre>
 
=={{header|PascalABC.NET}}==
{{trans|Nim}}
<syntaxhighlight lang="delphi">
procedure DisplayRange(first, last, step: integer);
begin
Print($'({first,2}, {last,2}, {step,2}): ');
if step = 0 then
Println('not allowed')
else Println(Range(first, last, step));
end;
 
begin
var ranges := |(-2, 2, 1), (-2, 2, 0), (-2, 2, -1),
(-2, 2, 10), (2, -2, 1), (2, 2, 1),
(2, 2, -1), (2, 2, 0), (0, 0, 0)|;
foreach var (f, l, s) in ranges do
DisplayRange(f,l,s);
end.
</syntaxhighlight>
{{out}}
<pre>
(-2, 2, 1): [-2,-1,0,1,2]
(-2, 2, 0): not allowed
(-2, 2, -1): []
(-2, 2, 10): [-2]
( 2, -2, 1): []
( 2, 2, 1): [2]
( 2, 2, -1): [2]
( 2, 2, 0): not allowed
( 0, 0, 0): not allowed
</pre>
 
 
 
=={{header|Perl}}==
1,003

edits