"Goto line" function?

Hi,

Fortunately the "goto" has been deprecated. It always results in spaghetti code. Check out 'case' control structure instead. You may want to think through the program flow so that you have each possibility and a default case for unanticipated situation. You will need to wrap your code inside the case structure. It's mo' better solution than coding ad hoc.

i = 3
case i
when 1, 2..5
print "1..5\n"
when 6..10
print "6..10\n"
end

Regards,

Joe

···

----- Original Message ----
From: Paul van Delst <Paul.vanDelst@noaa.gov>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Sent: Friday, March 9, 2007 6:40:05 PM
Subject: Re: "Goto line" function?

Helgitomas Gislason wrote:

Ok, I've read through the forum but I haven't got my answer. If a value
in my program is true, I want my program to go back to a line like this:

(Example of the program)

1. puts ' '
2. puts ' '
3. puts '****************************'
4. puts '** (Rules of the program) **'
5. puts '****************************'
6. puts ' '
7. puts 'Ohh, hello there! What are you named many names?'
8.
9. names = gets.chomp
10.
11. if names == '2'
12. puts ' '
13. puts 'Are you named two names?'
14. puts ' '
15. answer = gets.chomp
16. if answer == 'yes'
17. (the program continues)
18.
19. BUT if answer == 'no'
20. goto.line.7 (And skip the rules, just restart it and begin
from line 7.)

What is the command? I know it's not "goto.line.X" but what is it? "back
to line.X"? "goto.lineX"? What is the command?

Addressing just the loop/goto issue, how about summat like:

#!/usr/bin/env ruby
done=false
until done
   puts ' '
   puts ' '
   puts '****************************'
   puts '** (Rules of the program) **'
   puts '****************************'
   puts ' '
   puts 'Ohh, hello there! What are you named many names?'
   names = gets.chomp
   if names == '2'
     puts ' '
     puts 'Are you named two names?'
     puts ' '
     answer = gets.chomp
     done = true if answer == 'yes'
   end
end
#This is where "the program continues"
puts 'the end'

This gives me the output:

lnx:scratch : blah.rb

****************************
** (Rules of the program) **
****************************

Ohh, hello there! What are you named many names?
2

Are you named two names?

no

****************************
** (Rules of the program) **
****************************

Ohh, hello there! What are you named many names?
2

Are you named two names?

yes
the end

cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx

____________________________________________________________________________________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097

Where has this guy been the last decade?

···

On 9 mar, 21:20, Joseph Schiller <tendingc...@yahoo.com> wrote:

Hi,

Fortunately the "goto" has been deprecated. It always results in spaghetti code. Check out 'case' control structure instead. You may want to think through the program flow so that you have each possibility and a default case for unanticipated situation. You will need to wrap your code inside the case structure. It's mo' better solution than coding ad hoc.

i = 3
case i
when 1, 2..5
print "1..5\n"
when 6..10
print "6..10\n"
end

Regards,

Joe

----- Original Message ----
From: Paul van Delst <Paul.vanDe...@noaa.gov>
To: ruby-talk ML <ruby-t...@ruby-lang.org>
Sent: Friday, March 9, 2007 6:40:05 PM
Subject: Re: "Goto line" function?

Helgitomas Gislason wrote:
> Ok, I've read through the forum but I haven't got my answer. If a value
> in my program is true, I want my program to go back to a line like this:

> (Example of the program)

> 1. puts ' '
> 2. puts ' '
> 3. puts '****************************'
> 4. puts '** (Rules of the program) **'
> 5. puts '****************************'
> 6. puts ' '
> 7. puts 'Ohh, hello there! What are you named many names?'
> 8.
> 9. names = gets.chomp
> 10.
> 11. if names == '2'
> 12. puts ' '
> 13. puts 'Are you named two names?'
> 14. puts ' '
> 15. answer = gets.chomp
> 16. if answer == 'yes'
> 17. (the program continues)
> 18.
> 19. BUT if answer == 'no'
> 20. goto.line.7 (And skip the rules, just restart it and begin
> from line 7.)

> What is the command? I know it's not "goto.line.X" but what is it? "back
> to line.X"? "goto.lineX"? What is the command?

Addressing just the loop/goto issue, how about summat like:

#!/usr/bin/env ruby
done=false
until done
   puts ' '
   puts ' '
   puts '****************************'
   puts '** (Rules of the program) **'
   puts '****************************'
   puts ' '
   puts 'Ohh, hello there! What are you named many names?'
   names = gets.chomp
   if names == '2'
     puts ' '
     puts 'Are you named two names?'
     puts ' '
     answer = gets.chomp
     done = true if answer == 'yes'
   end
end
#This is where "the program continues"
puts 'the end'

This gives me the output:

lnx:scratch : blah.rb

****************************
** (Rules of the program) **
****************************

Ohh, hello there! What are you named many names?
2

Are you named two names?

no

****************************
** (Rules of the program) **
****************************

Ohh, hello there! What are you named many names?
2

Are you named two names?

yes
the end

cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx

____________________________________________________________________________________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.http://farechase.yahoo.com/promo-generic-14795097

don't blame him, I'm still learning TASM and GOTO's just like JMP

···

On 3/9/07, weber <hugows@gmail.com> wrote:

On 9 mar, 21:20, Joseph Schiller <tendingc...@yahoo.com> wrote:
> Hi,
>
> Fortunately the "goto" has been deprecated. It always results in
spaghetti code. Check out 'case' control structure instead. You may want
to think through the program flow so that you have each possibility and a
default case for unanticipated situation. You will need to wrap your code
inside the case structure. It's mo' better solution than coding ad hoc.
>
> i = 3
> case i
> when 1, 2..5
> print "1..5\n"
> when 6..10
> print "6..10\n"
> end
>
> Regards,
>
> Joe
>
> ----- Original Message ----
> From: Paul van Delst <Paul.vanDe...@noaa.gov>
> To: ruby-talk ML <ruby-t...@ruby-lang.org>
> Sent: Friday, March 9, 2007 6:40:05 PM
> Subject: Re: "Goto line" function?
>
> Helgitomas Gislason wrote:
> > Ok, I've read through the forum but I haven't got my answer. If a
value
> > in my program is true, I want my program to go back to a line like
this:
>
> > (Example of the program)
>
> > 1. puts ' '
> > 2. puts ' '
> > 3. puts '****************************'
> > 4. puts '** (Rules of the program) **'
> > 5. puts '****************************'
> > 6. puts ' '
> > 7. puts 'Ohh, hello there! What are you named many names?'
> > 8.
> > 9. names = gets.chomp
> > 10.
> > 11. if names == '2'
> > 12. puts ' '
> > 13. puts 'Are you named two names?'
> > 14. puts ' '
> > 15. answer = gets.chomp
> > 16. if answer == 'yes'
> > 17. (the program continues)
> > 18.
> > 19. BUT if answer == 'no'
> > 20. goto.line.7 (And skip the rules, just restart it and begin
> > from line 7.)
>
> > What is the command? I know it's not "goto.line.X" but what is it?
"back
> > to line.X"? "goto.lineX"? What is the command?
>
> Addressing just the loop/goto issue, how about summat like:
>
> #!/usr/bin/env ruby
> done=false
> until done
> puts ' '
> puts '****************************'
> puts '** (Rules of the program) **'
> puts '****************************'
> puts ' '
> puts 'Ohh, hello there! What are you named many names?'
> names = gets.chomp
> if names == '2'
> puts ' '
> puts 'Are you named two names?'
> puts ' '
> answer = gets.chomp
> done = true if answer == 'yes'
> end
> end
> #This is where "the program continues"
> puts 'the end'
>
> This gives me the output:
>
> lnx:scratch : blah.rb
>
> ****************************
> ** (Rules of the program) **
> ****************************
>
> Ohh, hello there! What are you named many names?
> 2
>
> Are you named two names?
>
> no
>
> ****************************
> ** (Rules of the program) **
> ****************************
>
> Ohh, hello there! What are you named many names?
> 2
>
> Are you named two names?
>
> yes
> the end
>
> cheers,
>
> paulv
>
> --
> Paul van Delst Ride lots.
> CIMSS @ NOAA/NCEP/EMC Eddy Merckx
>
____________________________________________________________________________________
> Finding fabulous fares is fun.
> Let Yahoo! FareChase search your favorite travel sites to find flight
and hotel bargains.http://farechase.yahoo.com/promo-generic-14795097

Where has this guy been the last decade?