Program:
1: formula (that is, code line, haha)
2: Termination of the program
Programs are composed of sub-statements. Use semicolons (;) or line breaks (;) to distinguish between formulas and formulas.
In the middle of a row, separate them with semicolons. If they are separated in two rows, they do not need semicolons ). However, if the backslash (\) is used
One row continues with the previous row.
Example: Print "Hello world! \ N "(as always Hello World)
- Statement:
Example: true (1 + 2) * 3foo () If test then OK else ng end
The ruby formula is filled with variables and constants, various types of direct quantities, operations and substitution, such as if and while control structures.
Call methods, define classes and methods. Operators can be grouped by parentheses. The null substatement () is returned as nil.
Ruby statements can return values or do not return values.
The following statements do not return values:
While, until, while modifier, until Modifier
In addition, for methods, you can specify parameters or do not specify parameters.
Do not specify the sub-statement of the method parameter:
And, or, not if/unless/rescue Modifier
If no parameter is specified, you can use it in parentheses to group it like a normal expression.
2. Termination of the program
The Ruby interpreter stops reading the following symbols.
End of File
^ D (Control Character D) and ^ Z (Control Character Z)
Only the rows with _ end _ (if there is blank above, it will not be recognized, that is, an error occurs)