Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
out of the calculation

Subject: out of the calculation

From: wahyoe Unggul

Date: 31 Mar, 2011 17:28:05

Message: 1 of 8

I make a statement, but can be run I can not get out of the calculation
done = false;
while not(done)
x=input('insert x')
m=1;
n=3;
  if (m<=x)&&(x<=n)
      for i=x
      disp('true')
       AM=20+x;
      continue
      end
  else
    disp('false')
  end
   
end
JK=AM+1
I mean, if the value of x is true, then it will go to the next calculation
Can you help me

Subject: out of the calculation

From: Florin Neacsu

Date: 31 Mar, 2011 17:40:20

Message: 2 of 8

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <in2dj5$rcu$1@fred.mathworks.com>...
> I make a statement, but can be run I can not get out of the calculation
> done = false;
> while not(done)
> x=input('insert x')
> m=1;
> n=3;
> if (m<=x)&&(x<=n)
> for i=x
> disp('true')
> AM=20+x;
> continue
> end
> else
> disp('false')
> end
>
> end
> JK=AM+1
> I mean, if the value of x is true, then it will go to the next calculation
> Can you help me

Do you ever change the value of "done" ?

Florin

Subject: out of the calculation

From: wahyoe Unggul

Date: 31 Mar, 2011 18:05:20

Message: 3 of 8

yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"

Subject: out of the calculation

From: ImageAnalyst

Date: 31 Mar, 2011 18:13:42

Message: 4 of 8

On Mar 31, 2:05 pm, "wahyoe Unggul" <wahyoe_slip...@yahoo.co.id>
wrote:
> yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"
-------------------------------------------------------------------------------------------------------------
What is the class of x? Is it a number? Is it a logical? What on
earth is it?

I don't see anywhere where you actually say something like
if (whatever)
    done = true;
end

You need that to get the loop to terminate. Calling disp() does not
set the value of done.

Subject: out of the calculation

From: Florin Neacsu

Date: 31 Mar, 2011 18:20:21

Message: 5 of 8

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <in2fp0$6un$1@fred.mathworks.com>...
> yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"

Well, that was my point. You are inside a while loop, which will continue until done=true. Hence, if you want to exit the loop you should change the value of done.

Right now, you code will never exit the while loop, because you never change "done" in either of if branches.

Also, what are you trying to do with " for i=x " ??

Regards,
Florin

Subject: out of the calculation

From: wahyoe Unggul

Date: 31 Mar, 2011 18:37:05

Message: 6 of 8

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <27c183f0-f181-4fc7-aa58-7ea41a8c48bf@i35g2000prd.googlegroups.com>...
> On Mar 31, 2:05 pm, "wahyoe Unggul" <wahyoe_slip...@yahoo.co.id>
> wrote:
> > yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"
> -------------------------------------------------------------------------------------------------------------
> What is the class of x? Is it a number? Is it a logical? What on
> earth is it?
>
> I don't see anywhere where you actually say something like
> if (whatever)
> done = true;
> end
>
> You need that to get the loop to terminate. Calling disp() does not
> set the value of done.

I'm sorry, "DISP ()" I just check the truth function "if" is already under way, shape my basic code like this.
x=input('insert x')
m=1;
n=3;
  if (m<=x)&&(x<=n)
      for i=x
        AM=20+x;
      end
  else
  disp('press enter, back to input')
  end
end
JK=AM+1

"x" is a value, if the value of "x"sign in "if (m <= x) & & (x <= n)" then the calculation will continue to calculate the next and continue until past the "end", if "x" does not match "(m <= x) & & (x <= n)" eating you will see "disp ('press enter, back to the input x')" will return to the "input".

Subject: out of the calculation

From: Florin Neacsu

Date: 31 Mar, 2011 18:50:05

Message: 7 of 8

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <in2hkh$lur$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <27c183f0-f181-4fc7-aa58-7ea41a8c48bf@i35g2000prd.googlegroups.com>...
> > On Mar 31, 2:05 pm, "wahyoe Unggul" <wahyoe_slip...@yahoo.co.id>
> > wrote:
> > > yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"
> > -------------------------------------------------------------------------------------------------------------
> > What is the class of x? Is it a number? Is it a logical? What on
> > earth is it?
> >
> > I don't see anywhere where you actually say something like
> > if (whatever)
> > done = true;
> > end
> >
> > You need that to get the loop to terminate. Calling disp() does not
> > set the value of done.
>
> I'm sorry, "DISP ()" I just check the truth function "if" is already under way, shape my basic code like this.
> x=input('insert x')
> m=1;
> n=3;
> if (m<=x)&&(x<=n)
> for i=x
> AM=20+x;
> end
> else
> disp('press enter, back to input')
> end
> end
> JK=AM+1
>
> "x" is a value, if the value of "x"sign in "if (m <= x) & & (x <= n)" then the calculation will continue to calculate the next and continue until past the "end", if "x" does not match "(m <= x) & & (x <= n)" eating you will see "disp ('press enter, back to the input x')" will return to the "input".


Hi,

I am sure that ImageAnalyst understood your disp command. He was just pointing out, that just by displaying true or false, it won't get you out of your loop.

In your initial posted code, try changing your line that says
"continue"
with
"done=true".

Does that help?

Florin

Subject: out of the calculation

From: wahyoe Unggul

Date: 31 Mar, 2011 19:04:05

Message: 8 of 8

"Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2ict$bc4$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <in2hkh$lur$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <27c183f0-f181-4fc7-aa58-7ea41a8c48bf@i35g2000prd.googlegroups.com>...
> > > On Mar 31, 2:05 pm, "wahyoe Unggul" <wahyoe_slip...@yahoo.co.id>
> > > wrote:
> > > > yes, I mean if the value of "x" is true, then the calculation can be continued, whereas if it is wrong it will go back to the "Input x"
> > > -------------------------------------------------------------------------------------------------------------
> > > What is the class of x? Is it a number? Is it a logical? What on
> > > earth is it?
> > >
> > > I don't see anywhere where you actually say something like
> > > if (whatever)
> > > done = true;
> > > end
> > >
> > > You need that to get the loop to terminate. Calling disp() does not
> > > set the value of done.
> >
> > I'm sorry, "DISP ()" I just check the truth function "if" is already under way, shape my basic code like this.
> > x=input('insert x')
> > m=1;
> > n=3;
> > if (m<=x)&&(x<=n)
> > for i=x
> > AM=20+x;
> > end
> > else
> > disp('press enter, back to input')
> > end
> > end
> > JK=AM+1
> >
> > "x" is a value, if the value of "x"sign in "if (m <= x) & & (x <= n)" then the calculation will continue to calculate the next and continue until past the "end", if "x" does not match "(m <= x) & & (x <= n)" eating you will see "disp ('press enter, back to the input x')" will return to the "input".
>
>
> Hi,
>
> I am sure that ImageAnalyst understood your disp command. He was just pointing out, that just by displaying true or false, it won't get you out of your loop.
>
> In your initial posted code, try changing your line that says
> "continue"
> with
> "done=true".
>
> Does that help?
>
> Florin
Florin, thank you very much, now it can work well

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us