Hack Forums
[Java] llegal return statement - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] llegal return statement (/showthread.php?tid=5087628)



llegal return statement - Unturned - Dec 9, 2015

Code
restaurants =
  [
    {"restaurant" : { "name" : "McDonald's", "food" : "burger" }},
    {"restaurant" : { "name" : "KFC",        "food" : "chicken" }},
    {"restaurant" : { "name" : "Pizza Hut",  "food" : "pizza" }}
  ];

for(var i = 0; i < restaurants.length; i++)
{
  if(restaurants[i].restaurant.food == 'chicken')
  {
    return restaurants[i].restaurant.name;
  }
}



* - +Haze - Dec 9, 2015

1) The code you posted looks like Javascript code and thus doesn't belong in the Java section. Java != Javascript.
Post it in this section.
Web Development

2) All of your recent programming threads are not descriptive, you just give a vague title and slap your code. We're not mind readers. Expand on what your problem is and what you aim to accomplish. Put some effort in your threads.

With that being said, I assume your issue is due to the fact that your code is not wrapped in a function and even if it was, you need another return statement incase your if statement doesn't execute.