0

this is a quick question, Im translating a program that's in C++ to C, and I saw this line of code,

for (int v : adj[u]) { 

referenced in this article: link

and I am not really sure what it does. I tried googling it and got results for range based for loops in C++, but cannot find anything that has this exact syntax and what it means. Help would be much appreciated.

3
  • 2
    en.cppreference.com/w/cpp/language/range-for Commented Jul 22, 2022 at 16:10
  • 1
    The missing piece is probably that adj is some sort of container of containers, which makes adj[u] a container that can be the range of a range-based for loop. Without knowing more about adj and adj[u] we can't really be more detailed. Commented Jul 22, 2022 at 16:11
  • All examples have exactly that syntax: it is for (<declaration> : <expression>). If you don't understand adj[u], look at the declaration of adj. Commented Jul 22, 2022 at 16:15

1 Answer 1

1

It's a very simple for loop that iterates over the elements of adj[u], going 1 by 1.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.