<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: no return statement?</title>
		<atom:link href="http://cycling74.com/forums/topic/no-return-statement/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/no-return-statement/feed</link>
		<description></description>
		<pubDate>Tue, 18 Jun 2013 23:24:31 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-30549</guid>
					<title><![CDATA[no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-30549</link>
					<pubDate>Wed, 28 Feb 2007 20:12:21 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;ve had this problem before in the past and never really figured it out (just re-worked everything to avoid it). In this simple little method, </p>
<p>public int[] noteOn()<br />
    {<br />
    int[] onEvent = new int[3];<br />
    for(int i=0;i < Margin;i++)<br />
      {<br />
      onEvent[0] = Colours.get(margin).intValue();<br />
	  onEvent[1] = Pitch;<br />
      onEvent[2] = Velocity;<br />
      return onEvent;<br />
      }<br />
    }</p>
<p>I&#8217;m getting an error of &#8220;missing return statement&#8221;. I don&#8217;t really understand why &#8212; I suppose it&#8217;s that there might be a situation in which the return is unreachable&#8230;</p>
<p>But I want to return multiple &#8220;onEvents&#8221;. Is there an easy way around the &#8220;missing return&#8221; problem?</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97836</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97836</link>
					<pubDate>Wed, 28 Feb 2007 20:18:13 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>hmm&#8230; I did this:</p>
<p>	public int[] noteOn()<br />
		{<br />
		int[] onEvent = new int[3];<br />
		onEvent[1] = Pitch;<br />
		onEvent[2] = Velocity;<br />
		for(int i=0;i < Margin;i++)<br />
			onEvent[0] = Colours.get(i).intValue();<br />
		return onEvent;<br />
		}</p>
<p>and it compiled (just re-positioning the for loop and leaving out the brackets!). But I&#8217;ve no idea whether it will actually return multiple &#8220;onEvent&#8221; arrays, one for each &#8220;Colour&#8221;???</p>
<p>I&#8217;ll try it later, when I have the class implemented. But if anyone knows a better way, or can help me understand the &#8220;missing return&#8221; error better, please post. Is it just that I&#8217;ve placed the return in a potentially unreachable spot?</p>
<p>cheers,</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97837</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97837</link>
					<pubDate>Wed, 28 Feb 2007 20:21:52 +0000</pubDate>
					<dc:creator>maxmspjit</dc:creator>

					<description>
						<![CDATA[
						<p>On 07-02-28, at 2012, jbmaxwell wrote:<br />
><br />
> I&#8217;ve had this problem before in the past and never really figured  <br />
> it out (just re-worked everything to avoid it). In this simple  <br />
> little method,<br />
><br />
> public int[] noteOn()<br />
>     {<br />
>     int[] onEvent = new int[3];<br />
>     for(int i=0;i < Margin;i++)<br />
>       {<br />
>       onEvent[0] = Colours.get(margin).intValue();<br />
> 	  onEvent[1] = Pitch;<br />
>       onEvent[2] = Velocity;<br />
>       return onEvent;<br />
>       }<br />
>     }<br />
><br />
> I&#8217;m getting an error of &#8220;missing return statement&#8221;. I don&#8217;t really  <br />
> understand why &#8212; I suppose it&#8217;s that there might be a situation in  <br />
> which the return is unreachable&#8230;<br />
><br />
> But I want to return multiple &#8220;onEvents&#8221;. Is there an easy way  <br />
> around the &#8220;missing return&#8221; problem?<br />
><br />
how big is Margin, and is margin the same? either way, putting a  <br />
return statement in your for loop means it may execute the first time  <br />
(i == 0), and then return. given that you don&#8217;t use i in the body of  <br />
your loop, and that it will only execute the loop once and exit, the  <br />
whole thing can be rewritten (w/o missing return statement error) as  <br />
follows:</p>
<p>public int[] noteOn()<br />
{<br />
     int[] onEvent = new int[3];</p>
<p>     onEvent[0] = Colours.get(margin).intValue();<br />
     onEvent[1] = Pitch;<br />
     onEvent[2] = Velocity;</p>
<p>     return onEvent;<br />
}</p>
<p>make sense? hope that helps.</p>
<p>r.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97838</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97838</link>
					<pubDate>Wed, 28 Feb 2007 20:28:18 +0000</pubDate>
					<dc:creator>maxmspjit</dc:creator>

					<description>
						<![CDATA[
						<p>On 07-02-28, at 2018, jbmaxwell wrote:<br />
><br />
> hmm&#8230; I did this:<br />
><br />
> 	public int[] noteOn()<br />
> 		{<br />
> 		int[] onEvent = new int[3];<br />
> 		onEvent[1] = Pitch;<br />
> 		onEvent[2] = Velocity;<br />
> 		for(int i=0;i < Margin;i++)<br />
> 			onEvent[0] = Colours.get(i).intValue();<br />
> 		return onEvent;<br />
> 		}<br />
><br />
> and it compiled (just re-positioning the for loop and leaving out  <br />
> the brackets!). But I&#8217;ve no idea whether it will actually return  <br />
> multiple &#8220;onEvent&#8221; arrays, one for each &#8220;Colour&#8221;???<br />
><br />
braces (not brackets) define a code block, and allow you to group  <br />
things that are more than one statement long. it&#8217;s not incorrect to  <br />
put a single statement into braces either, and in many cases makes  <br />
the code more readable.</p>
<p>your for loop is now setting the first item in onEvent (i.e., onEvent <br />
[0]) to something Margin number of times. there&#8217;s no point in doing  <br />
this, you&#8217;re just overwriting previous values with the value of  <br />
Colours.get(Margin).intValue();</p>
<p>I think what you&#8217;re likely really trying to do is return a 2D array:  <br />
3 values for each value of Margin. I would recommend reading up on  <br />
arrays (and java) to get a better understanding of what you&#8217;re trying  <br />
to accomplish.</p>
<p>r.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97839</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97839</link>
					<pubDate>Wed, 28 Feb 2007 20:45:47 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>Right. I get the idea. The point is that I have multiple options for &#8220;Colour&#8221;, but Pitch and Velocity remain the same. I assume from what you&#8217;ve said that my return might not have been reachable, which is why the method wouldn&#8217;t compile. Yes? It seems to me I&#8217;ve seen return statements in many places other than just the end in plenty of code, but every time I try it I get this error. I suppose all those times I&#8217;ve seen it were probably offering alternative return values&#8230; not sure. I&#8217;d have to find some examples and look more closely at them. Anyway, if the point is simply that I need to have at least one return that&#8217;s absolutely reachable, then I can avoid this problem in future.</p>
<p>I can certainly make a 2D array, and I may do that. To be honest, I hadn&#8217;t thought that much about it yet. I tried the above code, and it gave me that error I&#8217;d seen in the past, so I wanted to get to the bottom of it. I may also just find another way of approaching the whole problem. Not sure, but I&#8217;ll work it out. My java is probably a true freak show for any real programmer, but I&#8217;ve actually managed to do a lot with it! ;-)</p>
<p>cheers,</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97840</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97840</link>
					<pubDate>Wed, 28 Feb 2007 23:40:26 +0000</pubDate>
					<dc:creator>topher lafata</dc:creator>

					<description>
						<![CDATA[
						<p>Well first of all the method is declared to return an int array.<br />
If Margin was 0 the for loop would never be entered and hence<br />
there is no way for the method to return anything.</p>
<p>Also , if you were able to compile it, the way it is written you will  <br />
always return on the first iteration<br />
through the loop.</p>
<p>So, not understanding exactly what you are trying to do.<br />
Maybe the following will shed some light.</p>
<p>public int[] noteOn()<br />
{<br />
	int[] onEvent = new int[3];</p>
<p>		onEvent[0] =  Colours.get(margin).intValue();<br />
		 onEvent[1] = Pitch;<br />
		  onEvent[2] = Velocity;</p>
<p>
	return onEvent;</p>
<p>}</p>
<p>
if you wanted to return multiple events&#8230;</p>
<p>public int[][] noteOn()<br />
{<br />
	int[][] onEvent = new int[3][];<br />
	for(int i =0; i < onEvent.length;i++)<br />
	{<br />
		onEvent[i][0] =  Colours.get(margin).intValue();<br />
		 onEvent[i][1] = Pitch;<br />
		  onEvent[i][2] = Velocity;<br />
	}</p>
<p>	return onEvent;</p>
<p>}</p>
<p>
..although i don&#8217;t know what this would accomplish since I don&#8217;t<br />
have any idea what margin is.</p>
<p>if you can explain what you are trying to do more specifically someone<br />
might be able to better explain&#8230;</p>
<p>topher</p>
<p>> public int[] noteOn()<br />
>     {<br />
>     int[] onEvent = new int[3];<br />
>     for(int i=0;i < Margin;i++)<br />
>       {<br />
>       onEvent[0] = Colours.get(margin).intValue();<br />
> 	  onEvent[1] = Pitch;<br />
>       onEvent[2] = Velocity;<br />
>       return onEvent;<br />
>       }<br />
>     }</p>
<p>
On Feb 28, 2007, at 20:12 PM, jbmaxwell wrote:</p>
<p>><br />
> I&#8217;ve had this problem before in the past and never really figured  <br />
> it out (just re-worked everything to avoid it). In this simple  <br />
> little method,<br />
><br />
> public int[] noteOn()<br />
>     {<br />
>     int[] onEvent = new int[3];<br />
>     for(int i=0;i < Margin;i++)<br />
>       {<br />
>       onEvent[0] = Colours.get(margin).intValue();<br />
> 	  onEvent[1] = Pitch;<br />
>       onEvent[2] = Velocity;<br />
>       return onEvent;<br />
>       }<br />
>     }<br />
><br />
> I&#8217;m getting an error of &#8220;missing return statement&#8221;. I don&#8217;t really  <br />
> understand why &#8212; I suppose it&#8217;s that there might be a situation in  <br />
> which the return is unreachable&#8230;<br />
><br />
> But I want to return multiple &#8220;onEvents&#8221;. Is there an easy way  <br />
> around the &#8220;missing return&#8221; problem?<br />
><br />
> J.<br />
></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/no-return-statement/#post-97841</guid>
					<title><![CDATA[Re: no return statement?]]></title>
					<link>http://cycling74.com/forums/topic/no-return-statement/#post-97841</link>
					<pubDate>Thu, 01 Mar 2007 00:28:16 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>Quote: topher lafata wrote on Wed, 28 February 2007 23:40<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
> Well first of all the method is declared to return an int array.<br />
> If Margin was 0 the for loop would never be entered and hence<br />
> there is no way for the method to return anything.<br />
> </p>
<p>Yes, this is what I was thinking when I guessed that the method wouldn&#8217;t compile because of the possibility of not reaching the return statement. So that makes sense to me now. Code&#8230; it has so little faith! ;-)</p>
<p>
> Also , if you were able to compile it, the way it is written you will  <br />
> always return on the first iteration<br />
> through the loop.<br />
> </p>
<p>Yes, that&#8217;s what I intended. I wanted multiple returns, one for each &#8220;Colour&#8221;.</p>
<p>> So, not understanding exactly what you are trying to do.<br />
> Maybe the following will shed some light.<br />
> <br />
> public int[] noteOn()<br />
> {<br />
> 	int[] onEvent = new int[3];<br />
> <br />
> 		onEvent[0] =  Colours.get(margin).intValue();<br />
> 		 onEvent[1] = Pitch;<br />
> 		  onEvent[2] = Velocity;<br />
> <br />
> <br />
> 	return onEvent;<br />
> <br />
> }<br />
> <br />
> <br />
> if you wanted to return multiple events&#8230;<br />
> <br />
> public int[][] noteOn()<br />
> {<br />
> 	int[][] onEvent = new int[3][];<br />
> 	for(int i =0; i < onEvent.length;i++)<br />
> 	{<br />
> 		onEvent[i][0] =  Colours.get(margin).intValue();<br />
> 		 onEvent[i][1] = Pitch;<br />
> 		  onEvent[i][2] = Velocity;<br />
> 	}<br />
> <br />
> 	return onEvent;<br />
> <br />
> }</p>
<p>Right. This is the 2D array recommended earlier. That probably makes the most sense. I guess I just didn&#8217;t really see it as a 2D array, since it&#8217;s really [1 or more] versions of the same array with the first element changing its value&#8230;. but of course, that amounts to the same thing. Only I&#8217;d have to unpack the 2D array back in my calling class, but that&#8217;s not a big deal. The other option is just to return the &#8220;Colours&#8221; ArrayList with my pitch/vel array, then iterate through the ArrayList back in the calling class. All the info is going pretty much directly to an outlet, so it&#8217;s not that big a difference either way.</p>
<p>> <br />
> <br />
> ..although i don&#8217;t know what this would accomplish since I don&#8217;t<br />
> have any idea what margin is.<br />
> </p>
<p>Margin is just a range of choices for &#8220;colours&#8221; which are the sounds used to play pitch/vel &#8212; in my case they&#8217;ll be actual devices playing back the sounds, arranged qualitatively by colour. If the margin is one, I get one device playing the note, if it&#8217;s > 1 I get doublings, and so on.</p>
<p>> if you can explain what you are trying to do more specifically someone<br />
> might be able to better explain&#8230;<br />
> </p>
<p>I&#8217;ll work it out. I was really just curious about the &#8220;missing return&#8221; error. I understand that now, so I&#8217;ll continue gleefully mangling code.</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

