Android400 Android400 - 4 months ago 22
C++ Question

Why is this for loop not correct?

Visual Studio is telling me that this for loop isn't correct.
Error Messages are:

  • type bool unexpected

  • ok is undeclared identifier

  • missing ; before }


-recordset.Select return a long -MoveNext a bool

for (size_t i = 0, bool ok = recordset.Select(Adress::getSQLStatement() + "Where A05.recid = %ld", i); ok; ok = recordset.MoveNext(), i++) {


It's as StenSoft said. But you can define an anonymous structure in the loops first statement, and initialize that.

#include <iostream>
using namespace std;

int main() {
    for (struct {size_t i; bool ok;} s = {0, true}; s.ok; ++s.i) {
        s.ok = s.i < 10;
        cout << s.i;
    return 0;

But IMHO, while it works, it's more trouble than it's worth. Better restructure you code.