0

(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 + 2kgm + wm^2; s2 = (k^2 + (d - ((g1^2)y1[[i]]/wm))^2)gm + 2kwm^2; s3 = (k^2 + (d - ((g1^2)y1[[i]]/wm))^2)(wm^2) - (d - (g1^2 y1[[i]]/wm))wm(g1^2)(2y1[[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.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Lost
  • 226
  • 1
  • 7
  • 2
    Use Do instead of For (https://mathematica.stackexchange.com/questions/134609/why-should-i-avoid-the-for-loop-in-mathematica) – Michael E2 Oct 18 '21 at 12:40

1 Answers1

4

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 + 2kgm + wm^2; s2 = (k^2 + (d - ((g1^2)y1[[i]]/wm))^2)gm + 2kwm^2; s3 = (k^2 + (d - ((g1^2)y1[[i]]/wm))^2)(wm^2) - (d - (g1^2 y1[[i]]/wm))wm(g1^2)(2y1[[i]])]]]

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57