Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ array evaluation

Is there a way to "bulk evaluate" the contents of an array in C++? For example, let int numbers[10]={23,42,12,42,53,10,0,0,0,0}. Is there a way to loop through each element in the array and check whether the element meets a specified condition?

In short, I'd like to be able to do something like:

if(every element in the array meets arbitrary condition)
do this

or

if(array element from m to array element n==something)
do this

For small arrays, I know I could use something like: if(numbers[0]==blabla) && if(numbers[n]==blabla), then do this, but obviously this is not a realistic solution when it comes to evaluating very large arrays.

like image 751
Zubizaretta Avatar asked Sep 20 '26 07:09

Zubizaretta


1 Answers

you probably mean "for"

for(int i = 0; i < size_of_array; i++)
  if( the_condition_function(numbers[i])){
     //do this
  }
like image 180
Vladp Avatar answered Sep 21 '26 19:09

Vladp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!