이 코드를보십시오. 사람의 입력을 스캔하여 내부 배열과 일치하는지 확인하는 것이 바람직한 결과를 얻었습니다.줄 반복을 어떻게 멈출 수 있습니까?
sentence = []
compare = []
database_array = ["Mouse", "killer", "Blood", "Vampires", "True Blood", "Immortal" ]
def parser_sentence compare
database_array = ["Mouse", "killer", "Blood", "Vampires", "True Blood", "Immortal"]
initial_index = 0
while compare.count > initial_index
compare.each do |item|
if item == database_array[initial_index]
puts "You found the key word, it was #{item}"
else
puts "Sorry the key word was not inside your sentence"
end
end
initial_index = initial_index + 1
end
end
puts "Please enter in your sentences of words and i will parse it for the key word."
sentence = gets.chomp
compare = sentence.split (" ")
각 루프는 반복을 말하기 때문에 그렇게하지만 반복을 중지 할 수 있습니까?
입력에 대해 입력 및 출력을 추가하십시오. –
여기에'database_array'가 반복되는 이유가 있습니까? – tadman
@tadman 아마도 복사가 잘못된 것 같습니다. :) –