C++ for循环的使用

以前for循环的使用一直都是for(int i=0;i<10;i++)初始值,判断条件,变量处理这种形式用的,直到前两天看到有一个代码的写法是使用冒号,才知道原来C++还有这种写法。

#include<iostream>
using namespace std;

int main(){
	int a[]={1, 2, 3, 4, 6};
	for(int i : a){
		cout << i << endl;//1,2,3,4,6
	}
	return 0;
}
posted @ 2023-12-15 15:10  Danlis  阅读(5)  评论(0编辑  收藏  举报