Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,7 +1,10 @@
Quite often one needs loops which, in the last iteration, execute only part of the loop body. The goal of this task is to demonstrate the best way to do this.
Quite often one needs loops which, in the last iteration,
execute only part of the loop body.
The goal of this task is to demonstrate the best way to do this.
Write a loop which writes the comma-separated list
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
using separate output statements for the number and the comma from within the body of the loop.
using separate output statements for the number
and the comma from within the body of the loop.
See also: [[Loop/Break]]

View file

@ -1,2 +1,4 @@
---
category:
- Simple
note: Iteration

View file

@ -1,2 +1 @@
$ awk 'BEGIN{for(i=1;i<=10;i++){printf i;if(i<10)printf ", "};print}'
1, 2, 3, 4, 5, 6, 7, 8, 9, 10

View file

@ -0,0 +1,8 @@
BEGIN {
n=10
for(i=1;i<=n;i++) {
printf i;
if(i<n) printf ", "
}
print
}

View file

@ -6,7 +6,7 @@ func main() {
for i := 1; ; i++ {
fmt.Print(i)
if i == 10 {
fmt.Println("")
fmt.Println()
break
}
fmt.Print(", ")

View file

@ -0,0 +1,5 @@
for i = 1:10
print(i)
i == 10 && break
print(", ")
end

View file

@ -0,0 +1 @@
1, 2, 3, 4, 5, 6, 7, 8, 9, 10

View file

@ -0,0 +1,2 @@
> for i to 10 do printf( "%d%s", i, `if`( i = 10, "\n", ", " ) ) end:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10

View file

@ -0,0 +1,4 @@
(for (i 0 10)
(print i)
(unless (= i 10)
(print ", ")))

View file

@ -1,14 +1,20 @@
program numlist(output);
const MAXNUM: integer = 10;
var
i: integer;
begin
for i := 1 to 10 do
{ loop 1: w/ if branching }
for i := 1 to MAXNUM do
begin
write(i);
if i <> 10 then
if i <> MAXNUM then
write(', ')
end;
writeln;
{ loop 2: w/o if branching }
for i := 1 to MAXNUM-1 do
write(i, ', ');
writeln(MAXNUM);
end.

View file

@ -0,0 +1,7 @@
list='aa bb cc dd'
sep=', '
Do i=1 By 1 While list<>''
If i>1 Then Call charout ,sep
Parse Var list item list
Call charout ,item
End

View file

@ -0,0 +1,6 @@
(1..10).each do |i|
print i
break if i == 10
print ", "
end
puts

View file

@ -0,0 +1 @@
puts (1..10).join(", ")

View file

@ -1,6 +0,0 @@
for i in 1..10 do
print i
break if i == 10
print ", "
end
puts

View file

@ -0,0 +1,3 @@
object LoopAndHalf extends App {
println((1 to 10).mkString(", "))
}

View file

@ -0,0 +1,6 @@
for i in range(1, 10)
echon i
if (i != 10)
echon ", "
endif
endfor