0
$\begingroup$

(I did not know how to write this properly. Excuse me for that.)

For[x = 0.1, x < 3.5, x = x + 0.1,
 
 For[i = 1, i < 4, i++,

  If[y1[[i]] != 0, 
   s1 = k^2 + (d - ((g1^2)*y1[[i]]/wm))^2 + 2*k*gm + wm^2; 
   s2 = (k^2 + (d - ((g1^2)*y1[[i]]/wm))^2)*gm + 2*k*wm^2; 
   s3 = (k^2 + (d - ((g1^2)*y1[[i]]/wm))^2)*(wm^2) - (d - (g1^2*
          y1[[i]]/wm))*wm*(g1^2)*(2*y1[[i]]), Continue[]];

Here in place of Continue I want to go back to my inner loop ,i.e , if this If is not satisfied I want the inner for loop to run again. Thank you for the help.

$\endgroup$
1

1 Answer 1

4
$\begingroup$

there are several things wrong:

  • The "Continue[]" is not needed

  • You need 2 closing brackets at the end.

  • y1 should be a vector with values. y[[1]],y[[2]], y[[3] are not specified

  • I added two print statement in order that you can see what is going on

    y1 = {1, 0, 2};

    For[x = 0.1, x < 3.5, x = x + 0.1, For[i = 1, i < 4, i++,

    Print["{x,i}=", {x, i}];
    
    If[y1[[i]] != 0,
     Print["inside inner loop"]; 
     s1 = k^2 + (d - ((g1^2)*y1[[i]]/wm))^2 + 2*k*gm + wm^2;
     s2 = (k^2 + (d - ((g1^2)*y1[[i]]/wm))^2)*gm + 2*k*wm^2;
     s3 = (k^2 + (d - ((g1^2)*y1[[i]]/wm))^2)*(wm^2) - (d - (g1^2*
            y1[[i]]/wm))*wm*(g1^2)*(2*y1[[i]])]]]
    
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.