Old lady swallowed a fly: Difference between revisions

Content added Content deleted
(adding lambdatalk)
m (→‎{{header|Go}}: Formatted using gofmt, added comment punctuation, limited to 80 columns (assuming an indentation width of 8 spaces).)
Line 1,335: Line 1,335:


=={{header|Go}}==
=={{header|Go}}==
[https://play.golang.org/p/NwG13guusv Go Playground]
[https://play.golang.org/p/OV3YJSWxaJP Go Playground]
<lang go>package main
<lang go>package main


Line 1,341: Line 1,341:


var name, lyric, animals = 0, 1, [][]string{
var name, lyric, animals = 0, 1, [][]string{
{"fly", "I don't know why she swallowed a fly. Perhaps she'll die."},
{"fly", "I don't know why she swallowed a fly. Perhaps she'll die."},
{"spider", "That wiggled and jiggled and tickled inside her."},
{"spider", "That wiggled and jiggled and tickled inside her."},
{"bird", "How absurd, to swallow a bird."},
{"bird", "How absurd, to swallow a bird."},
{"cat", "Imagine that, she swallowed a cat."},
{"cat", "Imagine that, she swallowed a cat."},
{"dog", "What a hog, to swallow a dog."},
{"dog", "What a hog, to swallow a dog."},
{"goat", "She just opened her throat and swallowed that goat."},
{"goat", "She just opened her throat and swallowed that goat."},
{"cow", "I don't know how she swallowed that cow."},
{"cow", "I don't know how she swallowed that cow."},
{"horse", "She's dead, of course."},
{"horse", "She's dead, of course."},
}
}


func main() {
func main() {
for i, animal := range animals {
for i, animal := range animals {
fmt.Printf("There was an old lady who swallowed a %s,\n", animal[name])
fmt.Printf("There was an old lady who swallowed a %s,\n",
animal[name])


if i > 0 {
if i > 0 {
fmt.Println(animal[lyric])
fmt.Println(animal[lyric])
}
}


//Swallowing the last animal signals her death, cutting the lyrics short
// Swallowing the last animal signals her death, cutting the
// lyrics short.
if i+1 == len(animals) {
if i+1 == len(animals) {
break
break
}
}


for ; i > 0; i-- {
for ; i > 0; i-- {
fmt.Printf("She swallowed the %s to catch the %s,\n", animals[i][name], animals[i-1][name])
fmt.Printf("She swallowed the %s to catch the %s,\n",
animals[i][name], animals[i-1][name])
}
}


fmt.Println(animals[0][lyric] + "\n")
fmt.Println(animals[0][lyric] + "\n")
}
}
}</lang>
}</lang>