I. Judgment Structure
If Expression
Elsif expression
Else
End
IfExpression then end#Use then when writing a line
IfExpression#When the expression returns true, run the preceding code.
... Unless expression#When the expression is false, run the previous Code
Case expression
When condition 1 [, condition 2] [then]
When Condition 3 [, Condition 4] [then]
Else
End
Two-Cycle StructureWhileExpression
[Break[Expression]
End
Run the command when the expression value is true.CodeBlock. You can use break to exit or specify a value for break as the return value of the while loop.
While Expression
When the value of the following expression is true, the previous statement is executed cyclically. If the previous statement is a begin .. if the end block is used, execute begin first .. end block, and then determine whether to enter the next cycle, such:I=0
Begin
I+ = 1
Puts I
EndWhileI< 10
Until expression
End
Exit the loop until the expression value is true.
Until expression
Execute the statement until the expression value changes to true.
For Variable In Array
End
Retrieve an element from the array and traverse it. In Ruby, only .. in does not have a separate for, of course .. the usage frequency of in is not wide, and the most common in ruby is the each iterator that every array contains.
Break: exit the innermost loop, including while, until, for, and iteration. Break should not appear in case.
Next: Ignore the following code and enter the next loop.
Redo: do not check the cycle condition to start the current cycle again
Retry: restart the iterator