Loops: while and repeat-until

while loop works exactly like its counterpart in C# or C++, and repeat-until is analogous to do-while in those languages (or simply repeat-until in Pascal) with one exception. It always annoyed me that the latter loop does not create full scope, so I have to write such dreadful code as this:

{
  var loop_cond = false;
  do
  {
    loop_cond = ...
  }
  while (loop_cond);
}

The extra scope prevents leaking of control variable. In Skila repeat-until creates scope that ends after loop, so you can introduce variable inside loop and still use it in loop condition:

repeat
  var loop_cond = false;
  loop_cond = ...
until not loop_cond;

Note the lack of parentheses around loop condition. I have customized my keyboard layout but still typing no character is faster than typing single one.

Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: