[Courses] [Basics] Lesson #2: Data (II) - Variables, Lists, and a Loop
Sonja Krause-Harder
skh at gmx.com
Sun Apr 7 19:07:44 EST 2002
On Sun, Apr 07, 2002 at 03:16:22PM -0700, Liz Young wrote:
> On Saturday 06 April 2002 03:56 am, Sonja Krause-Harder wrote:
>
> > In practice, 'foreach' is used as follows:
> >
> > set $people {"Barney" "Fred" "Wilma" "Pebbles" "Dino"}
> >
> > foreach person $people {
> >
> > puts "Hello, $person!\n"
> >
> > }
>
> Is that a typo? To test myself that I learned something in Lesson #1 -
Yes, thanks for spotting it.
> set \$people {"Barney" "Fred" "Wilma" "Pebbles" "Dino"}
> foreach person $$people {
> puts "Hello, $person!\n"
> }
Or, of course, what should have been there:
set people {"Fred" "Barney" "Wilma" "Pebbles" "Dino"}
# ^ (no "$" here, that was the typo)
foeach person $people {
puts "Hello, $person!"
}
(Another version to put sense into that typo would have been:
set var_name people
set $var_name {"Barney" "Fred" "Wilma"}
foreach person $people {
puts $person
}
Can you figure out what's going on here?)
> Huh! It works... :-) Thanks,
I have to thank you ;-)
Sonja
More information about the Courses
mailing list