Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Both sides next revision
alvis:loop [2013/12/14 23:41]
marcin created
— (current)
Line 1: Line 1:
- ====== Loop statement ====== 
  
-Alvis provides two kinds of the **loop** statement (see Listing 1). The first statement repeats its contents infinitely. The second one repeats its contents while the **guard** g is satisfied. 
- 
- 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. 
- 
-<code> 
-  loop {...} 
-  loop (g) {...} 
-</code> 
- 
-**Listing 1. ** Loop statement syntax 
- 
- 
-<code> 
-x = 10; 
-y = x; 
-loop (y > 1) { 
-  y = y - 1; 
-  x = x * y; 
-} 
-</code> 
- 
-**Listing 2. ** Loop statement example 
- 
- 
-**[[:alvis:manual|Go back]]**