SunQuest
           Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old August 24th, 2007, 02:15 PM
incaps incaps is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 incaps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 58 sec
Reputation Power: 0
Repeating previous lines of code?

hi, i'm new to ruby. The tutorials i am learning from have a assignment to make an address book. i have wrote a poor but working script that holds address info in the script itself.

So far the program the program lists the available contacts
,states how many contacts you have, asks which contact you want to view and shows their details . It then asks if you would like to view another.

And that's where i am stuck i can't get the get the program to start over. Could someone point me in the right directions

cheers

Reply With Quote
  #2  
Old August 24th, 2007, 03:57 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 585 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 11 h 31 m 18 sec
Reputation Power: 67
Send a message via AIM to L7Sqr
without seeing your code structure, this is - at best - a shot in the dark.
I can only assume that you are doing what you are asked like so:
Code:
# pseudocode
build_tables
ask_for_input
show_appropriate_entry
However, you want to repeat the last two items for as long as the user is interested. In order to do that, simply put those two statements in a loop.
Code:
#pseudocode
build_tables
while user_wants_to_continue
   ask_for_input
   show_appropriate_entry
end


If that is not the case, please provide more information so that further answers will be more helpful.
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
  #3  
Old August 25th, 2007, 06:37 AM
incaps incaps is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 incaps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 58 sec
Reputation Power: 0
Sorry i should have added the code on the first post

#CONTACT LIST#


Contacts = [ 'Stephen ', 'Chris ', 'Catherine ', 'Michelle ', ] .sort


puts '---AVAILABLE CONTACTS---'
puts 'You have ' + Contacts .length .to_s + ' contacts

'

Contacts .each do |contact|

puts contact

end



puts " "
puts 'Which contacts address would you like?'

STDOUT .flush

Contact = gets .chomp


puts '

'
STDOUT .flush

#CONTACT INFORMATION#

case Contact
when "stephen ", "steve"
puts "hello steve"
puts 'do you not know your own address'
when 'Chris ' , 'chris'
puts 'street and house numer'
puts 'vilage'
puts 'town'
puts 'county'
puts 'postcode'
puts ' phone number'
when "Catherine ", 'katy'
puts 'street and house numer'
puts 'vilage'
puts 'town'
puts 'county'
puts 'postcode'
puts ' phone number'
when "Michelle ", 'shell'
puts 'street and house numer'
puts 'vilage'
puts 'town'
puts 'county'
puts 'postcode'
puts ' phone number'
else
puts "There are no contacts with this name"
end


puts " "
puts 'would you like any other address? '
STDOUT .flush

again = gets .chomp

Reply With Quote
  #4  
Old August 25th, 2007, 07:55 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 585 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 11 h 31 m 18 sec
Reputation Power: 67
Send a message via AIM to L7Sqr
For future reference, please use code tags (they help the formatting of the text).

When you do the first gets.chomp, you want to have your loop control directly before that (unless you want to print the list each time).
That can happen several ways, what follows is just one...

Code:
again = 'yes'
while again =~ /[Yy](es)?/

   #process your code as you have it

end
Or you can decide for a little cleaner approach, and combine the check with the data gathering
Code:
while gets.chomp =~ /[Yy](es)?/
   
   # process your code here

end


That should get you started. Post back with any more problems you encounter.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Repeating previous lines of code?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway