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

  • From: "tribble" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 24 Feb 2008 16:22:25 -0500

Hi Alex -- I still doubt the code you quoted is really what you want -- for 
one thing, do you want the loops to break when you hit an assignment? What 
exactly do you want the function to do? sIf you don't break when you hit the 
if/else you will have the problem of assigning ok multiple times. I agree 
with others that writing code and shifting it around until it compiles is 
dangerous -- runtime bugs are much harder to diagnose and correct than 
compile time bugs.
I only say this to ensure you indeed are hacking happily...*smile*
--le

----- Original Message ----- 
From: "Alex Hall" <mehgcap@xxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, February 23, 2008 11:59 PM
Subject: Re: method saying "no return statement" when there IS one


I had an if...else inside a double for loop, ensuring that no
slot of a 2d array was >=2.  I then moved the if outside of the
loops and got rid of the else completely, since I initialized the
variable that would be changed if a 2 or greater was encountered
to be okay.
The first try was like this (pretend all braces and declarations
are okay):
int ok=0; //1 is good, 0 is bad
for(i=0;i<grid.length;i++){
for(j=0;j<grid[i].length;j++){
if(grid[i][j]>=2){
ok=0;

else{
ok=1;



return ok;


Now the method that worked:
int ok=1; //1 is good, 0 is bad
for(i=0;i<grid.length;i++){
for(j=0;j<grid[i].length;j++){
if(grid[i][j]>=2){
ok=0;



return ok;



Have a great day,
Alex

> ----- Original Message -----
>From: "Marlon Brandão de Sousa" <splyt.lists@xxxxxxxxx
>To: programmingblind@xxxxxxxxxxxxx
>Date sent: Sat, 23 Feb 2008 22:49:29 -0300
>Subject: Re: method saying "no return statement" when there IS
one

>Hello Alex,
>This is not the way to follow if you want to learn programming.
You
>can't say "a, I changed this and I don't know why it is but it is
>working".  You need to understand what is going on, because may
be one
>day you won't be able to put the if else outside a loop and you
then
>don't know what to do.  I suggest you place your code here and
let us
>try to show you what's happenimg and why the compiler is
accepting the
>code or not deppending on what you're trying to achiev.
>Thanks
>Marlon

>2008/2/23, Alex Hall <mehgcap@xxxxxxx>:
>> Ah, got it! I had the if...else inside the for loops, and when I
>> moved them outside it was fine for some reason.  It now
compiles.

>> Have a great day,
>> Alex

>>> ----- Original Message -----
>>>From: "Ken Perry" <whistler@xxxxxxxxxxxxx
>>>To: <programmingblind@xxxxxxxxxxxxx
>>>Date sent: Sat, 23 Feb 2008 13:43:42 -0800
>>>Subject: RE: method saying "no return statement" when there IS
>> one



>>>I would have to see the code to know what is going wrong.

>>>Ken

>>>-----Original Message-----
>>>From: programmingblind-bounce@xxxxxxxxxxxxx
>>>[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
>> Hall
>>>Sent: Saturday, February 23, 2008 1:43 PM
>>>To: programmingblind@xxxxxxxxxxxxx;
>> programmingblind@xxxxxxxxxxxxx
>>>Subject: RE: method saying "no return statement" when there IS
>> one

>>>I just tried changing the method so I put an int into a variable
>> I called
>>>"ok", then return ok.  It now says that variable ok might not
>> have been
>>>initialized.  It was initialized at the start of the function,
>> however,
>>>right along with my i and j counters and there is no problem with
>> i or j.
>>>What am I doing wrong?????

>>>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


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




>--
>When you say "I wrote a program that crashed Windows," people
just
>stare at you blankly and say "Hey, I got those with the system,
for
>free."
>Linus Torvalds
>__________
>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

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

Other related posts: