While loop error, is not recognized

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

While loop error, is not recognized

renzosebs
Hi, I am trying to make a code in Octave and I don't know why while statement
is not working, is not being recognized as a  block in the function. This is
an image of it, notice how the function is ending with the endwhile, and the
for loop is not in the function, however the for is made as a block, but
while is not.
<http://octave.1599824.n4.nabble.com/file/t372838/Screenshot_20180427_225548.png>

If anyone can explain why this is happening, I will be vary grateful.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

marco atzeri-2
On 4/28/2018 5:57 AM, renzosebs wrote:

> Hi, I am trying to make a code in Octave and I don't know why while statement
> is not working, is not being recognized as a  block in the function. This is
> an image of it, notice how the function is ending with the endwhile, and the
> for loop is not in the function, however the for is made as a block, but
> while is not.
> <http://octave.1599824.n4.nabble.com/file/t372838/Screenshot_20180427_225548.png>
>
> If anyone can explain why this is happening, I will be vary grateful.
>
>

copy and paste please


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

Sahil
In reply to this post by renzosebs
renzosebs wrote

> Hi, I am trying to make a code in Octave and I don't know why while
> statement
> is not working, is not being recognized as a  block in the function. This
> is
> an image of it, notice how the function is ending with the endwhile, and
> the
> for loop is not in the function, however the for is made as a block, but
> while is not.
> &lt;http://octave.1599824.n4.nabble.com/file/t372838/Screenshot_20180427_225548.png&gt; 
>
> If anyone can explain why this is happening, I will be vary grateful.
>
>
>
> --
> Sent from:
> http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Hi
You haven't indented your code properly, that's the reason you're seeing it
closing at endwhile. While loop works well for me, the problem lies in
fprintf's syntax. If no FID is provided, it behaves exactly like printf().
So you should be doing fprintf("%d\n",z) instead. See the attached
screenshot for more.


<http://octave.1599824.n4.nabble.com/file/t372663/pp.png>



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

Andreas Weber-6
In reply to this post by renzosebs
Am 28.04.2018 um 05:57 schrieb renzosebs:
> Hi, I am trying to make a code in Octave and I don't know why while statement

crossposting on SO:
https://stackoverflow.com/questions/50072727/error-while-loop-octave-is-not-being-recognized

As explained there, you propably want "while (i < 10)"
and not "while (1 < 10)"


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

nrjank


On Sat, Apr 28, 2018, 06:50 Andreas Weber <[hidden email]> wrote:
Am 28.04.2018 um 05:57 schrieb renzosebs:
> Hi, I am trying to make a code in Octave and I don't know why while statement

crossposting on SO:
https://stackoverflow.com/questions/50072727/error-while-loop-octave-is-not-being-recognized

As explained there, you propably want "while (i < 10)"
and not "while (1 < 10)"

Looking at the * , I was wondering if the script was even saved with the edits he's displays. "Not recognized as a block" makes it sound like he wasn't even getting stuck in the while loop, which (1<10) would do.


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

renzosebs
In reply to this post by renzosebs
Thanks for your help. Yes, that was a mistake I made but the problem is not
that, is that while is not being closed. I dont have the scope that is
seeing in Sahil photo. The code is here:
function [i] = whale(a)
  b=a;
  i=0;
  while (i<10)
    i
    i=i+1;
  endwhile
  for z=1:i
    fprintf("%d", z);
  endfor
endfunction

But the problem is that the function end with the while, the endwhile is
closing the function and not the while loop. I hope this picture makes more
clear my problem.  

<http://octave.1599824.n4.nabble.com/file/t372838/Screenshot_20180428_092935.png>

Sorry for also posting in Stack, I am new in this thing od posting in
forums.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

Sahil
renzosebs wrote

> Thanks for your help. Yes, that was a mistake I made but the problem is
> not
> that, is that while is not being closed. I dont have the scope that is
> seeing in Sahil photo. The code is here:
> function [i] = whale(a)
>   b=a;
>   i=0;
>   while (i<10)
>     i
>     i=i+1;
>   endwhile
>   for z=1:i
>     fprintf("%d", z);
>   endfor
> endfunction

This code shows correct scope for me. Can share your Octave's version,
Operating System and answer to this command in octave:
"__octave_config_info__.hg_id" ?




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

renzosebs
Sure, thanks for your help.

Octave Version 4.2.2
OS: Manjaro . KDE 5.12.4, Kernel 4.14.34-1
>> __octave_config_info__.hg_id
ans = 94f8e2b5a88b



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

Doug Stewart-4
In reply to this post by renzosebs


On Sat, Apr 28, 2018 at 10:32 AM, renzosebs <[hidden email]> wrote:
Thanks for your help. Yes, that was a mistake I made but the problem is not
that, is that while is not being closed. I dont have the scope that is
seeing in Sahil photo. The code is here:
function [i] = whale(a)
  b=a;
  i=0;
  while (i<10)
    i
    i=i+1;
  endwhile
  for z=1:i
    fprintf("%d", z);
  endfor
endfunction

But the problem is that the function end with the while, the endwhile is
closing the function and not the while loop. I hope this picture makes more
clear my problem. 

<http://octave.1599824.n4.nabble.com/file/t372838/Screenshot_20180428_092935.png>

Sorry for also posting in Stack, I am new in this thing od posting in
forums.



This works ok for me!

Did you make a file called   while.m

use :
which while 

this should say nothing but if it shows a file then that is your problem.





--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

renzosebs
I don't have any file called while.m If i write "which while" nothing
happens.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: While loop error, is not recognized

renzosebs
I have uninstalled and installed again, and now It works. I don't really know
what was the problem but is ok now. Thank you to all.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html