Forum: Ruby How to "go to" in a RUBY script . . .

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-18 18:00
Hi,
Can someone tell me how to implement a "go to" kind of statement in
RUBY--GOTO, like in DOS or Windows scripts? If I do an "if" statement
for certain files in a directory, I want to "go to" other parts of the
program to execute certain stuff, kind of like a subroutine. In fact,
does RUBY have subroutines, or, does one simply use methods?

Thanks,
Peter
64a30f3037e399104d89d9ae1dddc6d4?d=identicon&s=25 Dor Kalev (Guest)
on 2006-05-18 18:06
Peter Bailey wrote:
> Hi,
> Can someone tell me how to implement a "go to" kind of statement in
> RUBY--GOTO, like in DOS or Windows scripts? If I do an "if" statement
> for certain files in a directory, I want to "go to" other parts of the
> program to execute certain stuff, kind of like a subroutine. In fact,
> does RUBY have subroutines, or, does one simply use methods?
>
> Thanks,
> Peter

Hi Peter, "goto" is an ancient philosophical paradigm.
These type of subroutines were replaced with functions (defined by 'def'
in ruby), it looks like this:

def print_hello(name)
 puts('Hello, '+name)
end

print_hello("Peter")
print_hello("Dor")
print_hello("Everyone")

the output will be:

Hello, Peter
Hello, Dor
Hello, Everyone
This topic is locked and can not be replied to.