hl

Sunday, 12 March 2017

Ruby Programming Language Tutorials Lec 05

Tutorial 5

Load code form other file

     In ruby to load code from other file we just is to type load and then write name of the file then it will load commands from the file .The extension of the file should be .rb . For example - we crete a file of  name rubyOrNotRuby.rb and in the file we write puts "Hello From rubyOrNotRuby2" and save it and execute it it will print Hello From rubyOrNotRuby2

In file rubyOrNotRuby2.rb                         Output        rubyOrNotRuby.rb             




Operators

   
     Let's study about some logical operators. In ruby there are 3 logical operators and or not

     And there is also some comparison operators like == != < > <= >=


Simple program on condition

     So let's make a program of checking age of a child if it is between 5 and 6 .He should be in kindergarten . If the age is between 7 and 13. He is in middle School.else .Stay at home so let's code it.
1. First of all make a age variable and give the the value 13
2. Make a condition if(age>=5)&&(age<=6)
3. Write you're in kindergarten puts "you are in kindergarten"
4. Make another condition elseif (age>=7)&&(age<=13)
5. Write you're in Middle school puts "you're in Middle school "
6. Write Yeah puts "Yeah"
7. else
8. Write Stay Home puts "Stay Home"
9. end
end is must in if condition

                     Input                                                                 Output











No comments:

Post a Comment