do while until end of array
-
how to use a Do While until of array?
constexpr int n = 9; char grid[n][n]; auto it=std::begin(grid); do { *(*it+1) = 'S'; // all fine } while (*it != end); // doesn't compile
-
@Natural_Bugger said in do while until end of array:
end
What do you mean by 'end' ?
I hope, it should be std::end(grid).
-
Thnx, but i tried that already.
well, i just want to loop of the length over the array.constexpr int n = 9; char grid[n][n]; auto it=std::begin(grid); do { *(*it+1) = 'S'; } while (*it != std::end(grid));
result in:
error: comparison between distinct pointer types βchar*β and βchar (*)[9]β lacks a cast [-fpermissive] 71 | } while (*it != std::end(grid)); | ^ error: comparison of distinct pointer types ('char *' and 'char *[9]')
-
hehe
do { *(*it+1) = 'S'; } while (it != std::end(grid));
i remove the "*" before "it" and it worked out.
-
error, it does compile.
but the code doesn't work.
no indication of error, it just doesn't do anything and doesn't execute the code below the "Do While" loop. -
@Natural_Bugger
If only there was a function that would take any container and iterate over all its values π€
oh!
right:constexpr int n = 9; char grid[n][n]; for( auto c : grid){ qDebug() << c; }
π
-
Thnx, i have multiple different "style" for loops in my source file going over the same array, all good.
i just wanted to try a "Do While", i don't need to access it values "perse", just stop at the end.