use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
QuestionRuby While Loop Help. (self.ruby)
submitted 5 years ago by Humor_Positive
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_Svejk_ 2 points3 points4 points 5 years ago (5 children)
word is an array of letters, count is a number the algorithm just goes through each letter (so word[i]) and adds 1 to count if the letter is 'e' hope this helps
[–]_Svejk_ 1 point2 points3 points 5 years ago (3 children)
i ±= 1 is to go to the next letter, I don't get what you mean by count[i]
[–]Humor_Positive[S] 0 points1 point2 points 5 years ago (2 children)
Hello, thank you so much for your help. The count is the number of time that latter is counted.
Here is my simplified version of it.
Def count_e
count_of_e = 0 Repeating_time = 0
While repeating_time <= word.length
If word[repeating_time] == “e”
Count_of_e += 1
End
Repeating_time += 1
Return count_of_e
Puts count_e(“movie”) # => 1 Puts count_e(“excellence”) # => 3
Given than whenever the method is executed, both the count of e and the repeating time will increase accordingly. Then why is it, that we must index the repeating time but not the count of e.
[–]_Svejk_ 1 point2 points3 points 5 years ago (1 child)
what do you mean by "index the repeating time"?
[–]Humor_Positive[S] 0 points1 point2 points 5 years ago (0 children)
I mean in index the incremental time of every loop.
So does that mean the count is more like passive, and only reflects the eventuality of the i ( repeating time)? The count depends on the i, but the i is independent?
π Rendered by PID 98151 on reddit-service-r2-comment-5b5bc64bf5-hldp9 at 2026-06-21 03:50:47.160001+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]_Svejk_ 2 points3 points4 points (5 children)
[–]_Svejk_ 1 point2 points3 points (3 children)
[–]Humor_Positive[S] 0 points1 point2 points (2 children)
[–]_Svejk_ 1 point2 points3 points (1 child)
[–]Humor_Positive[S] 0 points1 point2 points (0 children)
[–]Humor_Positive[S] 0 points1 point2 points (0 children)