I am supposed to get 2 in the output, but it is still -3 instead.
ClearAll[t, n];
n = -10;
While[True, If[n^2 + n - 6 == 0, Break[]]; n++];
t = n;
While[True, If[t^2 + t - 6 == 0, Break[]]; t++];
t
Is it possible to abort the 1st root(-3) and get 2nd root (2) with While loop code here?
t=-3before second loop and so second loops exists right away and sotdo not change? why do you thinktshould be2? – Nasser Mar 26 '20 at 03:36make second loop workis to get-3again fort, then you need to resetnback to-10again before you assign it totsincenhas changed after the first loop has finished. But may be you can clarify why you expected second loop to return2in the question itself, that would be best. – Nasser Mar 26 '20 at 03:40n = 0; n++; nand now is1and no longer zero. But it is possible I do not understand what the issue you are having in all of this and what exactly is the problem here. – Nasser Mar 26 '20 at 03:49n^2 + n - 6 == 0– kile Mar 26 '20 at 03:54