Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2c1d825

Browse files
author
runrevali
committed
[[ LCB Docs ]] Add documentation for LiveCode Builder language features
1 parent bf7bc37 commit 2c1d825

1 file changed

Lines changed: 157 additions & 2 deletions

File tree

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Library: control structures
1+
Library: com.livecode.language
22

33
Name: If
44

@@ -187,6 +187,161 @@ Step(number): The value by which to increase or decrease the <Counter>
187187
StatementList: A set of statements.
188188

189189
Example:
190+
public handler Factorial(in pOperand as integer) as number
191+
if pOperand < 1 then
192+
return 0
193+
end if
194+
195+
variable tTotal as number
196+
put 1 into tTotal
197+
198+
variable tCounter as integer
199+
repeat with tCounter from 1 up to pOperand
200+
multiply tTotal by tCounter
201+
end repeat
202+
203+
return tCounter
204+
end handler
205+
206+
Description:
207+
Use the repeat with <Counter> structure to execute a set of statements until the value of <Counter> reaches or crosses (depending on iteration direction) the value of <Finish>. The counter is increased (or decreased) by <Step> on each iteration of the loop.
208+
209+
Name: NextRepeat
210+
Type: control structure
211+
Summary: Begin the next iteration of a repeat loop.
212+
Syntax: exit repeat
213+
Example:
214+
variable tList as list
215+
variable tElement
216+
put [1, 2, 3, "a", 4, "b", 5] into tList
217+
218+
variable tSum as number
219+
put 0 into tSum
220+
repeat for each element tElement in tList
221+
if tElement is not a number then
222+
next repeat
223+
end if
224+
225+
add tElement to tSum
226+
end repeat
227+
228+
Description:
229+
Use <NextRepeat|next repeat> to skip to the next iteration of a repeat loop. This is particularly useful when operations are only to be performed on iterands which satisfy certain criteria.
230+
231+
Name: ExitRepeat
232+
Type: control structure
233+
Summary: Exit a repeat loop.
234+
Syntax: exit repeat
235+
Example:
236+
public handler ListUpToSentinel(in pList as list, in pSentinel as string) as list
237+
238+
variable tElement
239+
variable tNewList as list
240+
put the empty list into tNewList
241+
242+
repeat for each element tElement in pList
243+
if tElement is a string and tElement is pSentinel then
244+
exit repeat
245+
end if
246+
push tElement onto tNewList
247+
end repeat
248+
249+
return tNewList
250+
end handler
251+
Description:
252+
Use <ExitRepeat|exit repeat> to exit a repeat loop, for example when a certain condition is met.
253+
254+
255+
Name: Return
256+
Type: statement
257+
Syntax: return [<returnValue>]
258+
Summary: Causes execution of the current handler to end, and control return to the caller.
259+
260+
Parameters:
261+
returnValue (any): The value to return
262+
263+
Description:
264+
Use the return control structure to halt execution of the current handler, to return control to the caller, and optionally to return a value.
265+
Note: It is a checked runtime error for a value returned from a handler to not match the return type of the handler it is in.
266+
267+
Name: ThrowError
268+
Type: statement
269+
Syntax: throw <errorString>
270+
Summary: Causes an error to be raised.
271+
272+
Parameters:
273+
errorString (string): The error to throw.
274+
275+
Example:
276+
variable tVar as optional number
277+
put "Z" parsed as string into tVar
278+
if tVar is not defined then
279+
throw tVar && "is not a number
280+
end if
281+
282+
Description:
283+
The throw statement causes an error to be raised. This causes execution to terminate, and the error is passed back to environment.
284+
285+
The Error expression must be an expression that evaluates to a string.
286+
287+
Note: There is currently no try / catch mechanism in LiveCode Builder, so throwing an error will cause the error to be raised in LiveCode Script in the appropriate context.
288+
289+
Name: PutInto
290+
Type: statement
291+
Summary: Put a value into a container.
292+
Syntax: put <sourceValue> into <targetContainer>
293+
294+
Parameters:
295+
sourceValue (any): The value to put into the <targetContainer>
296+
targetContainer (any): A valid target for <sourceValue>
297+
298+
Description:
299+
Assigns the result of evaluating <sourceValue> to <targetContainer>.
300+
>*Note:* It is a checked runtime error for the source value's type to not be compatible with the target expression's type.
301+
302+
303+
Name: SetTo
304+
Type: statement
305+
Summary: Put a value into a container.
306+
Syntax: set <targetContainer> to <sourceValue>
307+
308+
Parameters:
309+
targetContainer (any): A valid target for <sourceValue>
310+
sourceValue (any): The value to put into the <targetContainer>
311+
312+
Description:
313+
Assigns the result of evaluating <sourceValue> to <targetContainer>.
314+
>*Note:* It is a checked runtime error for the source value's type to not be compatible with the target expression's type.
315+
316+
Name: Get
317+
Type: statement
318+
Summary: Evaluate an expression and put it into the result.
319+
Syntax: get <expression>
320+
Parameters:
321+
expression: Any expression.
190322

191323
Description:
192-
Use the repeat with <Counter> structure to execute a set of statements until the value of <Counter> reaches or crosses (depending on iteration direction) the value of <Finish>. The counter is increased (or decreased) by <Step> on each iteration of the loop.
324+
The get statement evaluates the Value expression and returns it as the result of the statement. The value is subsequently available by using <TheResult|the result> expression.
325+
326+
References: TheResult(expression)
327+
328+
Name: TheResult
329+
Type: expression
330+
Summary: The result of the previous statement.
331+
Syntax: the result
332+
Example:
333+
resolve script object "this stack"
334+
get property "name" of the result
335+
log the result
336+
337+
Example:
338+
get 20
339+
subtract 1 from the result
340+
divide the result by 2
341+
round the result
342+
-- the result is 10
343+
344+
Description:
345+
Use <TheResult|the result> to obtain the return value of the previous (executed) non-control structure statement.
346+
>*Note:* Result expressions are not assignable.
347+

0 commit comments

Comments
 (0)