If..Else :
- Executes code if the conditional is true. If the conditional is not true, code specified in the else clause is executed.
Syntax:
if conditional [then]
code...
[elsif conditional [then]
code...]
[else
code...]
end
Example:
If Modifier:
Syntax:
- Executes code if the conditional is true.
code if condition
Example:
Unless Statement:
- Executes code if conditional is false. If the conditional is true, code specified in the else clause is executed.
Syntax:
unless conditional [then]
code
[else
code ]
end
Example:
Unless Modifier:
- Executes code if conditional is false.
Syntax:
code unless conditional
Example:
Case Statement:
- Compares the expression specified by case and that specified by when using the === operator and executes the code of the when clause that matches.
Syntax:
case expression
[when expression [, expression ...] [then]
code ]...
[else
code ]
end
Example:
Ruby Loops:
While Statement:
- Executes code while conditional is true. A while loop's conditional is separated from code by the reserved word do, a newline, backslash \, or a semicolon ;.
Syntax:
while conditional [do]
code
end
Example:
While Modifier:
- Executes code while conditional is true.
Syntax:
code while condition
OR
begin
code
end while conditional
Example:
Until Statement:
- Executes code while conditional is false. An until statement's conditional is separated from code by the reserved word do, a newline, or a semicolon.
Syntax:
until conditional [do]
code
end
Example:
No comments:
Post a Comment