Ruby programming tutorial on loops. Ruby lesson.
★☆★ THE BEST EDITOR and IDE FOR PROGRAMMING ► http://bit.ly/Komodo-IDE-Learn-Ruby ★☆★
★☆★ SIGNUP TO GET MY RUBY BOOK FOR FREE ★☆★
http://bit.ly/free-book-signup
★☆★ FOLLOW ME BELOW ★☆★
Twitter ► http://bit.ly/jake-day-twitter
YouTube ► http://bit.ly/jake-day-youtube
Facebook ► http://bit.ly/jake-day-facebook
SoundCloud ► http://bit.ly/jake-day-soundcloud
★☆★ NOTES ★☆★
Topics discussed:
loop do, while, until, next if, break if
while
until
for variable in 1..30
loop do
-=
+=
=! not equal to
break
break if
next if
Amazon Auto Links: No products found.
Hey Jake, thanks very much for this Ruby series. It’s a really nice complement to books and online tutorials like Codecademy. Sometimes the tutorials can be really frustrating because the hint and Q&A board might not be enough to get you out of being stuck on a problem, killing your momentum and motivation.
As an extra means of practice, it would be really cool if your videos were accompanied by a description of exactly what will be accomplished in that lesson (i.e, written like a homework problem, just like the ‘Review’ exercises of the Codecademy lessons). That way, learners could try out the problem first if they think they might be able to do it on their own, and then use the video to check against their work or for help if they can’t make it run.
Hey Jake, why do i get the report “No such file or directory” …(LoadError)?
I have typed the same like you.
4:26 “so what that does is it makes bomb_timer negative one” – no, it is shorthand for subtracting one from bomb_timer
You didnt make a 13?
Hi, I was wondering if there is any difference in result between your code:
loop do
any_number -= 5
next if any_number % 2 != 0
puts “#{any_number}”
break if any_number <= 0 end and this: loop do any_number -= 5 puts "#{any_number}" if any_number % 2 == 0 break if any_number <= 0 end Thanks.
Why
. bomb_timer = bomb_timer – 1
instead of
. bomb_timer -= 1
???
You already used that construct in an earlier lesson, so why use the more verbose one here, and explain it all over again?
While I would not be anywhere near as rude as Jędrek, I do concur that you should have long since explained the use of the up arrow, which is actually pretty common on command-line systems, and switched to using that, probably taking the time to explain it for two to three videos and presuming people knew what was happening after that point, by simply saying “… and up arrow to recall the last command”. The drag and drop stuff is really, really, **really** tedious by this point…
Thx to the loops i coded my own loggin program… (with a calculator ;P)
(error)‘: undefined method “-” for nil:NilClass
Time_fix = 50
until Time_fix < = 20 puts Time_fix [line5] time_fix = time_fix - 1 end (then, in the prompt) --> :5:in ‘
what that means?
I’m using Ruby 2.1.5. Replicating your breaker.rb program; if I used < = it would return one minus integer after 0. If I used >= it would only output the first integer. I could get >= to go to 0; but it then would revert back to only outputting the first integer upon repetition. Is this a bug in Ruby or me?
You are such a great teacher! Thanks for explaining everything so simply.
yo dont put bomb timer or use that next time you make a video its mad weird listening to this video in public
I can ‘t understand the last example of loop do & next if 🙁
i capitalized the “t” in time_fix :=> (Time_fix)
it would print out a number and then a line stating the directory the file was in ending with
:5: warning: already initialized constant Time_fix
what does this mean exactly?
Why did you put puts “#{even}” using the speech marks-curly braces to print the next if loop, would puts even not have worked?
Did you know that pressing UP arrow on the keyboard invokes previousy used command in the ocmmand prompt? I watched 14 videos and got sick of you dragging and dropping ruby files into the command prompt. Noob!
These videos are extremely helpful and ive been waiting for the loops for a while. glad to finally get to it now!
love your videos, you should do the summary of some videos, and add challenges
3:54 It could also be represented as bomb_timer -= 1. Nice video.
Hey man , i am very much clear about all the concepts , but one i want to ask you , how much difficult would it be for me to switch from c# to ruby . currently i am working as a asp.net developer. completed 2 years of experience. Will it affect my salary package ??
Hi Jake,
Im confused regarding this code on the loop do:
no = 100
loop do
no -= 1
next if no % 2 != 0
puts “#{no}”
break if no <= 0 end Here is the reasoning as I understand it: (1) sets no to 100 (2) do the following (3) -1 from no to give 99 (4) next(I dont know what this next is for). If our no (99) does not have a remainder of zero after being divided by 2 (it doesnt in this case because the remainder is 1) then it outputs the number. But wouldnt this output be 99? Whenever I run the program it outputs 98, 96 and all the other even numbers. Please can you clarify?
Please go over how to use rails framework for development
You call “while” a method, but I believe “while” is a token.
Thanks for posting the video! This is great.
for those of you who are used to c, c++ etc. a do-while loop in c is a begin-end while in ruby. ex:
hp = 30
begin
hp -= 2
puts “Damage done, hp remaining #{hp}”
end while hp > 0
puts “Game Over”
So the loop goes to the next even number because the modulo is followed by “!=0”, meaning the odd number spits back a modulo that is not equal to zero, pushing the program to the next even number?