Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
if and unless statements are identical in sexpworld
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Sep 20, 2010
1 parent 587f541 commit c98c972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions 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 if condition then
conditional_code conditional_code
Expand All @@ -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`. 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.
2 changes: 1 addition & 1 deletion fixtures/if.rb
Expand Up @@ -5,4 +5,4 @@
what what
else else
them them
end end

0 comments on commit c98c972

Please sign in to comment.