+ 3

Why use unless instead of an if statement?

23rd Jul 2017, 8:24 AM
Kitty Cheese
Kitty Cheese - avatar
3 Réponses
+ 15
If a conditional expression evaluates to true, the if code is carried out. Otherwise, the code is ignored. On the other hand, the unless expression is the opposite of an if expression. It executes code when a conditional is false.  Both are useful for their own purposes. You can use any of them according to the need :]
23rd Jul 2017, 8:54 AM
Dev
Dev - avatar
+ 7
Kitty might like c++
23rd Jul 2017, 9:14 AM
jay
jay - avatar
+ 3
It just seems like you could use an if ! instead of an unless.
23rd Jul 2017, 9:12 AM
Kitty Cheese
Kitty Cheese - avatar