. View this ad or post your own Ruby Job!

Monday, October 31, 2005

Simple Constructs in Ruby

What have I found out so far?
  • Definition of Ruby
  • Ruby Windows Installer
  • Interactive Ruby - Open a new DOS window and type irb --simple-prompt A prompt appears as >>
  • Run a Ruby program by typing ruby hello.rb
  • Learnt some features of Ruby like comments, naming rules, variables, constants, strings etc.
  • Various Text Editors/IDEs like SciTE, NotePad2
Today, we shall explore some simple constructs available in Ruby. The example below illustrates the if else construct.
# if else
var = 5
if var > 4
puts "variable is greater than 4"
puts "I can have multiple statements here"
if var == 5
puts "nested if else possible"
else
puts "too cool"
end
else
puts "variable is not greater than 5"
puts "I can have multiple statements here"
end
Some common conditional operators are: ==, != >=, <=, >, <

Loops like the while are available. Again, the example below illustrates the same.
# Loops
var = 0
while var < 10
puts var.to_s
var += 1
end

First Post | Previous | Next


Technorati Tags:
Blogs linking to this article

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home

Valid XHTML 1.0!