loops - simple q on 'while' method in Ruby -
i writing "while" loop method below:
objective: find position of first letter that's vowel in give word "stackoverflow"
vowels = ["a","e","i","o","u",] word = "stackoverflow" n = 0 while vowels.include? word[n] == false n += 1 end print n
question: why n return 0? opposed 2 first "o" letter in "stackoverflow
operator precedence in while loop evaluation. try (vowels.include? word[n]) == false evaluate check vowel , compare false.
you face different issue if there no vowel in "word"
Comments
Post a Comment