'Why does a for-yet loop not exist?

I have learnt 4 kinds of iteration statements:

  1. for (also called fori or forj)
  2. while
  3. do-while
  4. foreach

Why pray, then does a for-still loop, not exist?


What are the use cases you ask?

  1. Same question can be asked for a do-while loop, where we can just substitute it with an appropriate if statement surrounded by a while loop.
  2. One use case I can think of is the following:
    (Just pseudo-code, 'cause well, this paradigm is language independent.
var stringToTokenize = 123,456,abc // expected output: string[] = { "123", "456", "abc"}

var token = "";

var[] tokens // (or string[], whatever)

// stringToTokenize will be referred to as str henceforth ('cause I am a lazy typist)

for(i = 0; i != str.length(); i++) {
    // token is complete, add to the array or list
    if (str[i] == ',') {
        tokens.add(token);
        //reset token
        token = "";
        continue;
    }
    token += str[i];
}

// one last time
tokens.add(token);

with a for-still loop this will become

for(i = 0; i != str.length(); i++) {
    // token is not complete
    if (str[i] != ',') {
        token += str[i];
        continue;
    }
    yet { // my made-up syntax
        // will run one last time
        tokens.add(token);
        //reset token
        token = "";
    }

}

Is there something inherently wrong with this kind of construct of was it just thought of and dismissed?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source