Item vs name


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-java/lessons/data-structures/exercises/hashmap-iterating?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
My code worked however i have a question. Why did we use “item” in the for loop --> for (String item: ) and not name?

```

Replace this line with your code.

<do not remove the three backticks above>

#2

That’s just the variable name they chose because it makes the most sense in that context. In the example it’s for(String name: ) because they are looping through a hashmap of people. in the code you type it’s for(String item: ) because they are looping through a hashmap of menu items. You can change that to any word and it would still run.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.