saving . . . saved While loop has been deleted. While loop has been hidden .
While loop
Title
Question
i=0:12;
while (j<=35)
j=1+2*i;
disp(j)
if (j==25)
then
break
end
end

correct output is displayed but going in infinite loop. 

Scilab Iteration 05-06 min 20-30 sec 07-05-20, 2:54 p.m. smitak

Answers:

The problem is that you think that j = 25 when it comes to the if statement.

Unfortunately, the value of j is the following:

[3 5 7 9 11 13 15 17 19 21 ...]

That is, j is a vector!  It can never be equal to 25!

The problem would have been solved if you had computed j once using j = 1+2*i. 

You should check each step and find out whether it is correct.  This can be done in Scilab, as it is an interpreted code. 

By the way, your code will not work (will not even go into the infinite loop), as j is not initalised.
07-05-20, 10:19 p.m. kannan
Thank you sir!! 
You are right 'J' is a vector here i thought its taking a single value at a time.
before executing above code i had tried with
i=0:12;
j=1+2*i;
so without initialization of 'j' i got vector J with [1 3...25] but not coming out of the loop, continuously displaying vector J.
still i am working on'The problem would have been solved if you had computed j once using j = 1+2*i.' to get correct answer.
 


08-05-20, 8:42 a.m. smitak

Login to add comment


3,5,7,9,11,13,15,17,19,21,23,25
07-05-20, 11:12 p.m. sanapganesh480@gmail.com


with i=o:12
output is [1 3 5...23 25] but not coming out of the loop continue to display
How to come out , working on that ,please check if one can help 
08-05-20, 8:46 a.m. smitak


Since you had defined i=0:12, the output is displaying an infinite loop. I have made the required changes in your code:

i=0;
j=0;
while (j<=35)
j=1+2*i;
disp(j)
i=i+1;
if (j==25)
then
break
end
end
08-05-20, 11:28 a.m. rashpat93
Yes!!
its working!! great,thanks a lot sir!!
I understood, because of i=0:12,'J' was also a vector and could not check break and come out of loop.
09-05-20, 4:31 p.m. smitak

Login to add comment


Log-in to answer to this question.