for loop : C++ and python

后端 未结 3 661
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 20:20

I understand how to use a for loop like

for (x = 0 ; x<5 ; x++ ) { // some_code }

in C++ but what about a for loop like

f         


        
3条回答
  •  感情败类
    2021-01-27 20:40

    The closest equivalent is a range based for-loop. For example,

    auto y = {0, 1, 2, 3, 4, 5, 6};
    
    for (auto i : y)
    {
      // do something with i
    }
    

    There are more details, but these depend on what you want to do. The C++ semantics are quite different to python's.

提交回复
热议问题