Scriptol/While Let

From Wikibooks, open books for an open world
Jump to navigation Jump to search

While Let[edit | edit source]

Common syntax[edit | edit source]

while x < 5
 print x
 x + 1

To increment a variable, Scriptol uses x + 1. This could not work in C and other languages.

Infinite loop in C[edit | edit source]

The C and C-like languages (C++, Java, C#) leads easily into infinite loop. Here hare two simple examples.

while(x < 5);
  printf("%d\n", x);
  x += 1:

Perhaps you have instantaneously noticed it (and perhaps no), but the construct is bad, due to the semi-colon after the condition!

Another example without the misplaced semi-colon:

while(x < 10)
  printf("%d\n", x);
  if(x = 5) continue;
  ... some statements ...
  x += 1;