This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathif.lcdoc
More file actions
141 lines (110 loc) · 4.43 KB
/
Copy pathif.lcdoc
File metadata and controls
141 lines (110 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Name: if
Type: control structure
Syntax:
if <condition> then
<statementList>
[else
<elseStatementList>]
end if
Syntax:if <condition> then
<statementList>
[else if <condition> then
<elseifStatementList>]
[else
<elseStatementList>]
end if
Summary:
Evaluates a <condition|conditional expression> to determine if it is true
and if so <execute|executes> a subsequent <statement> or <statementlist|statement list>.
If the <conditional expression|condition> is false and the <if> <control structure> contains
an <else> keyword the <statement> or <statementlist|statement list> following the <else>
<keyword> is executed.
The <if> <control structure> may contain one or more <else if> <keyword|keywords> which have a
<condition|conditional expression>. If the <condition|conditional expression> for one of these evaluates to be
true then the <statment|statement> or <statementlist|statement list> following that <else if>
<keyword> is executed.
If the <if> <control structure> contains
more than one line then the <if> <control structure> must end with an <end if> keyword.
Introduced: 1.0
OS: mac, windows, linux, ios, android
Platforms: desktop, server, mobile
Example:
if tSpeed < 2 then
answer "That is slow"
else if tSpeed < 5 then
answer "That is pretty fast"
else if tSpeed < 10 then
answer "That is a rocket"
else
answer "You are traveling at the speed of light"
end if
Parameters:
condition (bool):
Any <expression>. (If the <condition> <evaluate|evaluates> to true,
the <statement|statements> execute for that <condition>.
If the <condition> <evaluate|evaluates> to false, the <statement> or
<statementlist|statement list> following that <condition> is
skipped.)
statementList:
Of one or more <LiveCode> <statement|statements>, and can also include
<if>, <switch>, <try>, or <repeat> <control structure|control
structures>.
elseIfStatementList:
Of one or more <LiveCode> <statement|statements>, and can also include
<if>, <switch>, <try>, or <repeat> <control structure|control
structures>.
elseStatementList:
Of one or more <LiveCode> <statement|statements>, and can also include
<if>, <switch>, <try>, or <repeat> <control structure|control
structures>.
Description:
Use the <if> <control structure> to <execute> a <statement>
(or <statementlist|list of statements>) only under certain circumstances.
The <if> <control structure> always begins with the word if. There
are four forms of the <if> <control structure>:
if condition then statementList [else elseStatementList]
This form may have a line break before the words `then` or `else` or both.
if condition then
statementList
[else
elseStatementList]
end if
-- OR
if condition
then statement
[else
elseStatementList]
end if
-- OR
if condition then
statementList
else elseStatement
end if
If the <condition> <evaluate|evaluates> to true, the statement or
<statementList> is <execute|executed>; if the <condition>
<evaluate|evaluates> to false, the statement or <statementList> is
skipped.
if the <condition> evaluates to false and the <if> <control structure>
contains an <else> <keyword>, the <elseStatement> or <elseStatementList>
which follows it is <execute|executed>.
If the <if> <control structure> contains one or more <else if>
<keyword|keywords> which have a <condition|conditional expression>,
and one of those <condition|conditional expressions> evaluates to be
true, then the respective <elseIfstatement|else if statement> or
<elseIfstatementlist|else if statement list> following that
<else if> <keyword> is executed.
If one <if> <control structure> is nested inside another, use of the
second form described above is recommended, since the other forms may
cause ambiguities in interpreting which <else> clause belongs with which
<if> statement.
The <if> <control structure> is most suitable when you want to check a
single <condition>. If you need to check for multiple possibilities,
doing something different for each one, use
a <switch> <control structure> instead.
>*Note:* The <if> <control structure> is implemented internally as a
> <command> and appears in the <commandNames>.
References: repeat (control structure), switch (control structure),
try (control structure), commandNames (function),
statement (glossary), command (glossary), evaluate (glossary),
execute (glossary), control structure (glossary), then (keyword),
else (keyword), else if (keyword), end if (keyword), word (keyword)