Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

llegal return statement

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;
  }
}
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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by blackcoder00Mar 11, 2019 07:20 AM 5 245 Mar 11, 2019 07:20 AM
Last Post: blackcoder00
[Java] by KusoApr 30, 2017 07:23 AM 11 414 Apr 30, 2017 07:23 AM
Last Post: Owl
[Java] by Woe Is MeOct 9, 2015 04:27 PM 5 135 Oct 9, 2015 04:27 PM
Last Post: Astigmatism