2016-07-25 22:53:33 +02:00
|
|
|
# Sequencing
|
2016-07-02 16:18:39 +02:00
|
|
|
|
2016-07-25 22:53:33 +02:00
|
|
|
By calling one function after another, in sequence, you can create an animation:
|
2016-07-02 16:18:39 +02:00
|
|
|
|
|
|
|
```typescript
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .
|
2016-07-25 22:53:33 +02:00
|
|
|
`);
|
2016-07-02 16:18:39 +02:00
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
# . . . #
|
2016-07-25 22:53:33 +02:00
|
|
|
`);
|
2016-07-02 16:18:39 +02:00
|
|
|
```
|
|
|
|
|
2016-07-25 22:53:33 +02:00
|
|
|
### The semicolon
|
2016-07-02 16:18:39 +02:00
|
|
|
|
2016-07-25 22:53:33 +02:00
|
|
|
In JavaScript, the semicolon (;) is used to terminate (or end) a statement. However, in most
|
|
|
|
cases, the semicolon is optional and can be omitted. So both code sequences below are
|
|
|
|
legal:
|
2016-07-03 00:27:49 +02:00
|
|
|
|
2016-07-25 22:53:33 +02:00
|
|
|
```typescript
|
2016-07-26 06:45:39 +02:00
|
|
|
basic.showNumber(1)
|
|
|
|
basic.showNumber(2)
|
2016-07-25 22:53:33 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
```typescript
|
2016-07-26 06:45:39 +02:00
|
|
|
basic.showNumber(1);
|
|
|
|
basic.showNumber(2);
|
2016-07-25 22:53:33 +02:00
|
|
|
```
|
|
|
|
|
2016-07-26 06:46:14 +02:00
|
|
|
### The empty statement
|
2016-07-25 22:53:33 +02:00
|
|
|
|
|
|
|
In JavaScript, there is the concept of an *empty statement*, which is whitespace followed by
|
|
|
|
a semicolon in the context where a statement is expected.
|
|
|
|
So, the following code is an infinite loop
|
|
|
|
followed by a call to `showNumber` that will never execute:
|
2016-10-23 06:29:31 +02:00
|
|
|
```typescript-ignore
|
|
|
|
while(true) ;
|
2016-07-26 06:45:39 +02:00
|
|
|
basic.showNumber(1);
|
2016-07-25 22:53:33 +02:00
|
|
|
```
|
2016-07-25 23:00:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
### ~hint
|
2016-11-02 01:44:37 +01:00
|
|
|
For the @boardname@, we don't allow a program to contain an empty statement, such as shown above.
|
2016-07-25 22:53:33 +02:00
|
|
|
If you really want an empty statement, you need to use curly braces to delimit an empty statement block:
|
|
|
|
```typescript
|
2016-07-26 06:45:39 +02:00
|
|
|
while(true) { }
|
|
|
|
basic.showNumber(1);
|
2016-07-25 22:53:33 +02:00
|
|
|
```
|
2016-07-25 23:00:51 +02:00
|
|
|
### ~
|
2016-07-25 22:53:33 +02:00
|
|
|
|
|
|
|
[Read more](http://inimino.org/~inimino/blog/javascript_semicolons) about semicolons in JavaScript.
|
|
|
|
|
2017-03-07 19:17:01 +01:00
|
|
|
### ~button /javascript/variables
|
2016-07-25 22:53:33 +02:00
|
|
|
NEXT: Variable Declarations
|
|
|
|
### ~
|