Saturday, April 18, 2015

Learning Ruby part III

Starting flow control.
If statements.
Behavior as expected. Note the comparison operator uses double equals ==. A single = is an assignment operator.
Note that elsif is not spelled correctly. That took me a while to realize why the code didn't work right.
unless checks for false value, opposite of if
exclamation as a prefix is like "not" -- != means "not equal"
&& conjunction
|| disjunction
How to use if, else, and elsif
How to use comparators / relational operators like ==, !=, <, <=, >, and >=
How to use boolean / logical operators like &&, ||, and !

String control with a daffy duckifyer. gsub

Check substrings .include?

Starting loops
while, until, for
no increment operator like ++ or --
instead, uses += with an delta value
range in 1...10 (exclude the end value) or in 1..10 (include end value)

loop method -- the iterator
break to exit a loop
next to skip an iteration
arrays to store multiple values
another iterator .each

No comments:

Post a Comment