Re: method saying "no return statement" when there IS one

  • From: "tribble" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 24 Feb 2008 15:26:20 -0500

Well, you need a return at the end of the function after the loops to catch 
the boundary condition that the j loop never executes.
But look at your code again: aren't you always returning on the first 
iteration of the j loop, assuming the j loop executes?  Are you sure you 
want to do this?
--le



----- Original Message ----- 
From: "Alex Hall" <mehgcap@xxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, February 22, 2008 10:46 PM
Subject: method saying "no return statement" when there IS one


Hi all.  Yet again I have what to many of you is no doubt a very
simple question, but it is not making sense.  I have a method
that is checking collisions on a battleship grid.  It is an
integer method that returns 0 if a collision is detected and 1 if
there is no problem.  The compiler, however, keeps saying that I
am missing a return statement when I clearly have two, one in an
if statement and the second in a related else.  Here is the
method:

public static int checkCollisions(int[][] grid){
int i,j;
for(i=0;i<grid.length;i++){
for(j=0;j<grid[i].length;j++){
if(grid[i][j]<=2){
return 0;

else{
return 1;





Have a great day,
Alex
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: