Ruby Simplified Part 4: Ruby Loops

Let’s look at some Ruby loop constructs: for, while, and until.

# .Each loop
x = 10
x.times do |i|        
    puts "#{i}"    # Starts at 0, ends at 9
end

# For loop
for i in 0..10 do  # Needs a range
    puts "#{i}"    # Starts at 0, ends at 10
end

# While loop
x = 0
while x < 10
    puts "#{x}"    # Starts at 0, ends at 9
    x += 1
end

# Until loop
x = 0
until x >= 10 do
    puts "#{x}"    # Starts at 0, ends at 9
    x += 1
end

Ruby also supports break and next, these are equivalent to break and continue in C#.

# Break
for i in 0..10
    if i > 5
        break      # Terminate the most internal loop
    end
    puts "#{i}"    # Will print 0 1 2 3 4 5
end

# Next
for i in 0..10
    if i < 5
        next
    end
    puts "#{i}"    # Will print 5 6 7 8 9 10
end
Advertisements

Twitter

In a few years we’ll all be ashamed that we used Twitter.

– Me

My top 20 non-developer apps

I recently got a new laptop (Vista Ultimate x64) and was wondering what apps I would load, so here’s my top 20… 

  1. Firefox (no brainer)
  2. AVG or Avast! (anti-virus software)
  3. Adobe Reader (unfortunately can’t do without)
  4. Notepad++ (Replace the old but trusty Notepad)
  5. µTorrent (very lightweight Bittorrent client)
  6. Picasa (photo view and share)
  7. VLC (play any media file)
  8. CCleaner (system cleaning tool)
  9. Mozy (free 2GB auto backups!)
  10. KeePass (manage your online passwords) 
  11. WinZip or WinRAR (compression tools)
  12. Net Nanny (Internet Filter)
  13. Spybot Search & Destory (rid your PC of spyware)
  14. Windows Live SkyDrive (25GB free online storage)
  15. Dropbox (sync files across computers)
  16. Paint .NET (replace the aging MS Paint)
  17. Digsby (for all your IM needs)
  18. Skype (phone calls for free)
  19. Quick Media Converter (for my iPhone needs)
  20. WinDirStat (folder sizes)

(For developer apps and tools take a look at Scott Hanselman’s list).

Hello World!

The obligatory “Hello World!” first post!

About me: I work as a software developer with .NET technologies, in Seattle.

Disclaimer
The information in this weblog is provided “AS IS” with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. The opinions expressed herein are solely by own. Inappropriate comments will be deleted at the authors discretion. All code samples are provided “AS IS” without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time, snapshot you should not consider out of date posts to reflect my current thoughts and opinions.