-
-
Save zhangw/055ed2c3d642c8e8f300 to your computer and use it in GitHub Desktop.
Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts "hello" | |
| p "hello" | |
| my_name = "Carole" | |
| def salut(name) | |
| p "hello" + " " + name | |
| end | |
| salut(my_name) | |
| def greeting | |
| puts "Enter your name : " | |
| name = gets.chomp | |
| puts "Hello " + name | |
| end | |
| greeting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (5+5==10) | |
| puts "this is true" | |
| else | |
| puts "this is false" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def choose | |
| puts "do u like programming? Yes or No please" | |
| choice = gets.chomp | |
| if (choice.downcase == "yes") | |
| puts "That\'s great!" | |
| elsif (choice.downcase == "no") | |
| puts "That\'s too bad!" | |
| else | |
| puts "That was not a yes or a no." | |
| end | |
| end | |
| choose | |
| def choisir | |
| puts "Do you like programming? Yes, no, or maybe please." | |
| choix = gets.chomp | |
| case choix.downcase | |
| when "yes" | |
| puts "That\'s great!" | |
| when "no" | |
| puts "That\'s too bad!" | |
| when "maybe" | |
| puts "Glad you are giving it a chance!" | |
| else | |
| puts "I have no idea what that means." | |
| end | |
| end | |
| choisir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #3.times do | |
| #puts "Hello!" | |
| #end | |
| #number = 0 | |
| # while (number <= 10) do # while this condition is true, do... | |
| # p "the number is now #{number}" # whatever is in this code block | |
| # number += 1 # short for number = number + 1 | |
| # end # don’t forget your end | |
| (0..10).each do |n| | |
| p "the new number is #{n}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment