do while until end of array
-
wrote on 16 Aug 2020, 10:02 last edited by Natural_Bugger
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
-
wrote on 16 Aug 2020, 10:08 last edited by
@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).
-
@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).
wrote on 16 Aug 2020, 10:13 last edited by Natural_BuggerThnx, 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]')
-
@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).
wrote on 16 Aug 2020, 10:17 last edited byhehe
do { *(*it+1) = 'S'; } while (it != std::end(grid));
i remove the "*" before "it" and it worked out.
-
wrote on 16 Aug 2020, 10:21 last edited by
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. -
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; }
😉
-
@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; }
😉
wrote on 16 Aug 2020, 10:35 last edited by Natural_Bugger@J-Hilk
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. -
wrote on 16 Aug 2020, 15:54 last edited by
Hi,
this
do {
*(*it+1) = 'S';
} while (it != std::end(grid));
doesn't never end because the iterator is not incremented! (endless loop)
1/8