Forums Register Login

missing return statement error from the FOR loop

+Pie Number of slices to send: Send
May i know what should i do if i want to return some thing from the loop in side a method.

please note: i want to print the string 2 times(twice)



[ March 08, 2008: Message edited by: Rauhl Roy ]
+Pie Number of slices to send: Send
The compiler is complaining because it's possible to call the method using an empty String ("") of length zero, in which case the loop body will never execute, so your method will be missing a return statement.

Keep in mind that when you "return" from a method, that method is done executing. So if you expect to iterate through the length of the String, you don't want to return during the first iteration.

I'm not exactly sure what you're trying to do here, but it looks like one approach might be to create a StringBuilder in the method, append it with each iteration of the loop, and then return a String representation of the StringBuilder after you've finished looping.
+Pie Number of slices to send: Send
Marc is perfectly correct, your confusion might be cleared now.
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2358 times.
Similar Threads
What is the sequence of execution?
StringBuffer question
Static and Instance Blocks..
Reading a file from a directory.
Help with class initialization
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:17:32.