#need help about a loop

1 messages · Page 1 of 1 (latest)

copper ibex
#

i saw this code in freecodecamp,

for(Person person : persons){
  person.HelloWorld;
}

and i'm still confused what they meant here, can someone explain?

meager furnaceBOT
#

<@&987246399047479336> please have a look, thanks.

meager furnaceBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

sacred yarrow
#

Well the person : persons is just a loop over the list of persons. Easier way than writing it with int i = 0; i< persons.size... It's called forEach Loop. Downside: you don't have the index in the loop. But most of the time you dont need that.

tardy relic
#

the part inside the loop is pretty dumb though, it doesnt do anything

#

like this part here person.HelloWorld;

#

makes no sense

sacred yarrow
#

Yes it would not compile. As it's not a method call without ()

#

Or at least it would do nothing

tardy relic
#

it does compile

#

if its a field

#

but it doesnt do anything besides accessing it and not using it for anything

#

but yeah

raven saddle