tutorial ruby - Check the flow with the conditions
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 :
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.
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
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
- 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
Permissions in this forum:
You cannot reply to topics in this forum