tutorial net
*********WOOOOOOW *********
We're happy to see you're enjoying our races (already 5 pages viewed today)! You can keep checking out by becoming a member of the tutorial net community. It's free!
You will also be able to keep track of your race progress, practice on exercises, and chat with other members.

Share
Go down
Admin
Posts : 207
Join date : 2017-11-11
Age : 28
Location : algeria
View user profilehttp://www.tutorial-net.com

tutorial ruby - Check the flow with the conditions

on Sun Apr 01, 2018 7:34 pm
The basic syntax of a condition
As in the previous chapter, we will create an empty Ruby file, entitled conditions.rb, which we will modify as we go along and test in the console. I invite you to create this file and place your console in its directory.

Once these conditions are met, discover the conditions in this video!
Conditions can be added to perform different actions in Ruby as the case using keywords if, else, elsif :
Code:
if trajet_minutes > 120
  puts "Prends un film avec toi"
elsif trajet_minutes < 5
  puts "Pas le temps de t'asseoir..."
else
  puts "Tu as le temps de lire au moins quelques chapitres d'un bouquin !"
end
Conditions can be combined with the signs && (for "AND") and || (for "OR").

Booleans are useful variables for testing whether a condition is true or false. In the example below, code_indenté is a boolean that is true or false.
Code:
if code_indenté
  puts "Bravo, ton code est bien indenté !"
else
  puts "Pense à bien indenter ton code pour améliorer sa lisibilité !"
end
To check an equality condition, two equal signs (==) must be used. Be careful not to be confused with the equal sign (=) used to assign a value to a variable:
Code:
age = 18 #range la valeur 18 dans la variable age et renvoie donc 18
age == 18 #booléen qui renvoie True si age vaut 18, False sinon
Well, you've done the basics of Ruby, I hope you enjoyed it! See you in the next part to go to the next level with object-oriented programming.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum