Loops/Wrong ranges: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 1,961:
{{trans|Python}}
<syntaxhighlight lang="langur">
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.
▲for .i in 2..len(.table) {
▲ .table[.i] = map [.f, .f, .f, _], .table[.i]
}
for
val
{
val
catch {
writeln "{{
} else {
writeln "{{
}
}
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}}==
|