Is there a for each loop in V5 Text?

The title basically says it all. We were trying to loop through the objects in the vision sensor’s sight and tried doing a for each loop and couldn’t get one to work. If someone could post an example it would be greatly appreciated.

Well there are for loops in C++, hence VEXcode Pro V5 Text has for loops!
https://www.learncpp.com/cpp-tutorial/57-for-statements/

There are a lot of other resources about using the Vision sensor.
Using the search bar will give even more than the ones I have included below.



4 Likes

While these don’t directly answer my question I’ll take a look through these resources and see what I can learn.

1 Like

Well there are for loops in C++, hence VEXcode Pro V5 Text has for loops!

C++ is a programming language. You can even use it outside of VEXcode. Since C++ has a for loop, you can use a for loop in VEXcode.

1 Like

Well elaborating off of the code shown here:

And here (also linked in my post above):

Since you can choose which object you are looking at, you could probably say something along the lines of:

take snapshot;
int objectcount= how many objects are in snapshot;

for (0 to (objectcount - 1))
    if size of object # is greater than x
        add 1 to a list;
    else
        add 0 to a list;

if (the first int in list is 1)
    printf("The first object has a size greater than x");

That is mostly pseudo code though, so you would have to figure out the commands and execution. I think that this code would work, but I haven’t had time to try it. It would also help to know exactly what you are trying to do.

2 Likes