|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 Code:
while gets.chomp =~ /[Yy](es)?/ # process your code here end That should get you started. Post back with any more problems you encounter. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Repeating previous lines of code? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|