0

Hello everyone,
i tried to make a program with Ruby but i came up with results who doesn't help me.
somehow the result doesn't show up as i requested.

letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z']

name = "bbb"

i=0
j=0
k=0

for i in 0..25 do
for j in 0..25 do
for k in 0..25 do

trying = letters[i]+letters[j]+letters[k]

        if trying == name
            puts "matched"
            puts name
            else
            puts "not matched"
        end



end 
end
end 

i=1+i
j=1+j
k=1+k       

system("pause")

Edited by curlissue657: lenght of the page

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
0

You could modify your code to work like this:

letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z']

name = "bbb"

i=0
j=0
k=0

blnFound = false

for i in 0..25 do
   for j in 0..25 do
      for k in 0..25 do

         trying = letters[i]+letters[j]+letters[k]
         if trying == name
            blnFound = true
            puts "matched"
            puts name
            break            
         else
            puts trying
        end
      end

      if blnFound
         break
      end
   end
   if blnFound
      break
   end
end 

system("pause")
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.