5/6 Control Flow Know-How - why the extra end?


#1


This works only after the second 'end' is put in. Need help understanding what exactly each 'end' is ending.


puts "Text to search through: "
text = gets.chomp

puts "Word to redact?"
redact = gets.chomp

words = text.split(" ")

words.each do |word|
    
    if word == redact
        print "REDACTED "
    else
        print word + " "
end
end


#2

@scriptmaster67781,
One END is used the close the IF ELSE END statement
the other END is used to close the each do statement.


#3

Thanks! I figured as much but wanted to confirm. Coming from learning JS first, Ruby's loosey-goosey ways take some getting used to!


#4

@scriptmaster67781,
I Always go on the look out what other programmers were thinking
by using a google search
== discussions ./ opinions ==
ruby [your question] site:stackoverflow.com

OR

google search
== the Book ==
jquery [your question] site:developer.mozilla.org
CSS [your question] site:developer.mozilla.org
javascript [your question] site:developer.mozilla.org
[your question] site:jquery.com
[your question] site:getbootstrap.com

== discussions / opinions ==
jquery [your question] site:stackoverflow.com
CSS [your question] site:stackoverflow.com
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
[your question] site:crockford.com
- - http://javascript.crockford.com/code.html << Javascript coding convention
- - http://javascript.crockford.com/survey.html

http://stackoverflow.com/questions/1795438/load-and-execution-sequence-of-a-web-page
http://www.w3schools.com/jquery/trysel.asp
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
++ bootstrap
http://getbootstrap.com/getting-started/
http://getbootstrap.com/2.3.2/components.html
We now have .col-xs (phones), .col-sm (tablets), .col-md (desktops), and .col-lg (large desktops).


#5

Thanks or the tips! I'm studying Ruby now for admission to a coding bootcamp. Ultimately it's about understanding the concepts & principles underlying all the languages -- that's something I'm trying to do now - basically, getting the higher level understanding so I can write the actual code easily.


#6

@scriptmaster67781,
Then Always be aware which version of Ruby you are working with.....
what i use

https://www.ruby-lang.org/en/documentation/

https://en.wikibooks.org/wiki/Ruby_Programming
https://en.wikibooks.org/wiki/Ruby_Programming#Ruby_language
http://ruby-doc.org/stdlib-2.3.0/libdoc/json/rdoc/index.html

http://docs.ruby-lang.org/en/2.0.0/Object.html
http://docs.ruby-lang.org/en/2.0.0/Array.html
http://docs.ruby-lang.org/en/2.0.0/String.html
http://docs.ruby-lang.org/en/2.1.0/Hash.html


#7

The reason that there is two ends is because one is closing the each loop and the other is closing the if else that is within the each loop.

Hope this helped you to understand it makes it a whole ton easier to code when you understand i know from experience and soon you will to. Have a great day.