• plistig@feddit.de
    link
    fedilink
    arrow-up
    18
    ·
    edit-2
    1 year ago

    A semicolon ends a statement, and semicolon is a statement on its own. One that does nothing. That’s why you can write

    int i;
    for (i = 0; i ᐸ 3; i++);
    

    to set i = 3. You can use that pattern to find something in an iterator, etc. But I would prefer

    int i = 0;
    while (i ᐸ 3) {
       i++;
    }
    

    for readability.