Basic syntax (if while case for continue exit try)

Source: Internet
Author: User

If table
Syntax: If <expr1> then <expr2> [else <expr3>]
Syntax: If <expr1> DO <expr2>
<Expr1> is a test expression. The evaluation result must be true or false.
If the test result is true,
<Expr2> after then or do is executed
The result is the return value of the IF expression.

 

Case tabulation
The case expression compares the results of a test expression with tags of a series of label expressions.
Select a Tag expression from the result for evaluation.
Syntax: case [<expr>] of (<cases>)
<Expr> is a test expression, and <cases> is a sequence of expressions with tags. Its syntax is:
<Factor>: <expr>
Default: <expr>
-----------------------------------------------
New_obj = case copy_type.state
(
2: Copy $ foo
3: instance $ foo
Default: Reference $ foo
)
---------------------------------------------------------------
If an expression is used as a tag, brackets must be used to enclose the expression. For example:
Case
(
(A> B): Print "A is big"
(B <C): Print "B is little"
(C <= D * 3 ):...
Default :...
)

While Loop
The while and do loops are used to repeatedly execute an expression until the test expression evaluates to false.
Syntax: While <expr> DO <expr>
<Expr> after while is the test expression. If the test expression returns true, It will be executed repeatedly.
<Expr>
--------------------------------
X = 10
While X> 0 do
(
Print x
X-= 1
)

For Loop
Syntax: For <var_name> (in | =) <sequence> (do | collect) <expr>
<Var_name> is the name of the cyclic index variable, and <sequence> is the source value of the loop.
It can be in the following forms:
<Expr> to <expr> [by <expr>] [where <expr>]
<Expr> [where <expr>]
--------------------------------------------------------
For I = 1 to 10 do print I -- numerical sequence
For item in [able] do X = x + item. height -- array Sequence
For T in of to Loof by 5f do -- time series in frames
Bigones = for OBJ in $ box *
Where obj. Height> 100 collect OBJ -- put the box with a height greater than 100 in the array
------------------------------------------
The <sequence> format has an optional where <expr>. The result must be true or false.
The where expression is evaluated before the loop is executed. The loop is executed only when its result is true.
In the DO <expr> form, the for loop simply calculates the values of the expressions in <expr> in each loop.
The Circular Variable <var_name> is visible in the circular body <expr>
------------------------------------------------
Collect <expr> form of the for loop to collect the result of <expr>
And store them in an array, and the array is used as the return value of the for loop.

Continue sentence
Used to directly jump to the end of a loop in a for, do, and while loop, and then start the next loop
For I = 1 to 8 do (if I = 5 do continue; print I) -- print 1 .. 4, 6 .. 8
-----------------------------------------------
While not eof f do -- read the file until the end of the file
(
Local line = Readline f -- read a row
If line [1] = "-" Do continue -- if it is a comment row, skip this row
Line1 = parser1 line -- call the function parser1
Processobjs line1 -- call the function processobjs
)

Exit statement
Exit the loop in the for, do, and while loop in advance, even if the value of the Loop Test expression is still true
Syntax: exit [with <expr>]
The optional with <expr> option allows the user to specify the returned value of the loop body when the loop is exited in advance,
If with <expr> is not specified, the returned value is undefined.
From a... Exit with <expr> to exit the do loop. The returned value is OK.
From a... The collect loop exits with exit with <expr>. The returned value is an array composed of elements collected before exiting.
----------------------------------------
While x <y do
(
Local Delta = x-y
If Delta <= 0 Then exit
$ Foo. Pos. x = compute_x (FOO/delta)
X + = 0.1
)

Try table
Capture any running errors in the code segment, so that the corresponding response can be taken when an error occurs.
Syntax: Try <protected_expr> catch <on_err_expr>
<Protected_expr> is the expression for capturing running exceptions.
Once a running error is found, <on_err_expr> will be executed
If <protected_expr> is a block expression, the execution stops at the row where an error occurs.
If no running error occurs, <on_err_expr> will not be executed
---------------------------------------------------------------
F = openfile "foo. dat"
Try
While not eof f do read_some_data F
Catch
(
MessageBox "Bad Data in Foo. dat"
Results = undefined
)
Close F
Any errors found when calling the read_some_data () function will be captured.
Then a message box is displayed.

 

Basic syntax (if while case for continue exit try)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.