source: src/Clight/test/controlflow.c

Last change on this file was 2388, checked in by campbell, 7 years ago

Example of each type of control flow statement, plus minor fix to matita
pretty printer.

File size: 538 bytes
Line 
1/* Produce an example of each control flow structure. */
2
3int main(void) {
4  int i,j,x;
5
6  x = 0;
7
8  i=10;
9  while (i) {
10    if (i%2) x++;
11    i--;
12  }
13
14  /* The removal of side effect in the expression --i causes CIL to output a
15     for loop instead */
16  i=5;
17  do {
18    if (i%2) x+=2; else x+=3;
19  } while (--i);
20
21  /* This version stays a do...while */
22  i=5;
23  do {
24    if (i%2) x+=2; else x+=3;
25    --i;
26  } while (i);
27
28  for (i=7; i>2; i-=2) {
29    j=i;
30    while (j--) {
31      if (j<i/2) break;
32      x++;
33    }
34  }
35
36  return x;
37}
Note: See TracBrowser for help on using the repository browser.