I'm working on a program that needs to iterate over a range.
I wish to know if I can use continue
like when I use in range based for loop.
Working :
std::vector<std::string> v = {"foo", "bar", "baz", "foobar"};
for (auto s : v)
{
if (*s.front() == 'b')
continue;
std::cout << s << std::endl;
}
Not-Working :
std::vector<std::string> v = {"foo", "bar", "baz", "foobar"};
std::for_each(v.begin(), v.end(), [](const std::string& s) {
if (*s.front() == 'b')
continue;
std::cout << s << std::endl;
});
Replace continue
with return
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With