我了解如何使用 for 循环
for (x = 0 ; x<5 ; x++ ) { // some_code }
在 C++ 中,但是像
这样的 for 循环呢?for x in y:
至少在 python 中存在
最佳答案
最接近的等效项是基于范围的 for 循环。例如,
auto y = {0, 1, 2, 3, 4, 5, 6};
for (auto i : y)
{
// do something with i
}
还有更多细节,但这些取决于你想做什么。 C++ 语义与 Python 的完全不同。
关于python - for 循环 : C++ and python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22157497/