Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Both sides next revision | ||
alvis:loop [2017/01/11 22:41] marcin removed | — (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | | ||
- | Alvis provides three kinds of the **loop** statement (see Listing 1). The first statement repeats its contents infinitely. The second one repeats its contents while the **guard** '' | ||
- | |||
- | A **guard** is a Haskell logical expressions placed inside round brackets. | ||
- | |||
- | |||
- | The contents of a loop must be put inside curly brackets and it must contain at least one statement. | ||
- | |||
- | The **loop** statement is a multi-step statement. The first step consists of evaluating the guard (if any) and entering the corresponding loop. Then, a model executes steps inside the loop. | ||
- | |||
- | In case of non-time models, the **loop every** statement works in the same way as the **unguarded loop**. | ||
- | |||
- | In case of time models, the user must ensure that the duration of the loop content does not exceed the loop period. Otherwise, the loop will restart its work after finishing the previous cycle. | ||
- | |||
- | The **loop every** statement must contain the **null** statement as its last loop statement. It is necessary for the current version of the compiler to proceed the loop correctly. | ||
- | |||
- | < | ||
- | loop {...} | ||
- | loop (g) {...} | ||
- | loop (every t) {...; null;} | ||
- | </ | ||
- | |||
- | **Listing 1. ** Loop statement syntax | ||
- | |||
- | |||
- | < | ||
- | x = 10; | ||
- | y = x; | ||
- | loop (y > 1) { | ||
- | y = y - 1; | ||
- | x = x * y; | ||
- | } | ||
- | </ | ||
- | |||
- | **Listing 2. ** Loop statement example | ||
- | |||
- | |||
- | **[[: |