Permalink
Browse files

if and unless statements are identical in sexpworld

  • Loading branch information...
1 parent 587f541 commit c98c97252a1f8310113d3b298719efa92766a750 @radar radar committed Sep 20, 2010
Showing with 8 additions and 4 deletions.
  1. +7 −3 explanations/if.md
  2. +1 −1 fixtures/if.rb
View
10 explanations/if.md
@@ -1,8 +1,11 @@
-## `if` statement
+## `if`/`unless` statement
+The `if` statement is used for when we want to conditionally run code.
-The `if` statement is used for when we want to conditionally run code. A common `if` syntax is this:
+`unless` is the opposite of `if`. Where `if` will run the code if it evaluates to something that is not `nil` or `false`, `unless` will run its contained code _only_ if the condition evaluates to `nil` or `false`.
+
+A common `if` syntax is this:
if condition then
conditional_code
@@ -26,4 +29,5 @@ A shorter way to write this would be to use a _ternary statement_, which looks l
In this example the `?` indicates the beginning of the code to run when the `if` evaluates to `true`. After that code, we use `:` to denote what code should be ran if the `condition` evaluates to `false`.
-**Please note**: `if` statements that can be condensed to one line will be output as ternary examples, where as multi-lined `if` statements will be output as such with `then` after the condition.
+
+**Please note**: `if` statements that can be condensed to one line will be output as ternary examples, where as multi-lined `if` statements will be output as such with `then` after the condition.
View
2 fixtures/if.rb
@@ -5,4 +5,4 @@
what
else
them
-end
+end

0 comments on commit c98c972

Please sign in to comment.