Schleifen, Bedingungen & Co.

Remove["Global`*"]

/;

f[x_] := -x^10  /;  
          x ≤  0;
f[x_] := x^2  /;  x > 0;
p1 = 
        Plot[f[x], {x, 1, 2}, AxesOrigin -> {1, 0}, 
          PlotRange -> {-2, 4}];
p2 = 
        Plot[f[x], {x, -1.1, 1.5}, AxesOrigin -> {0, 0}, 
          PlotRange -> {-2, 4}];

Show[p1, p2];

Show[p2, p1];

Do

Do[s[i, k] = i*k; 
      Print[TableForm[Table[s[ii, kk], {ii, 1, i}, {kk, 1, k}]]], {i, 1, 
        5}, {k, 1, 5}]

While

i = 1; k = 3;
s[i_, k_] := i*k;
While[
i ≤ 5, 
Print[
        TableForm[
          Table[s[ii, kk], {ii, 1, i}, {kk, 1, k}]]]; 
i = 
        i + 1]

i = 1; k = 1;
s[i_, k_] := i*k;
While[
(i ≤ 
            5)  &&  (k ≤ 5), 
Print[
        TableForm[
          Table[s[ii, kk], {ii, 1, i}, {kk, 1, k}]]]; 
i = 
        i + 1; k = k + 1]

For

For[
(i = 1)  && (k = 
            3), 
(i ≤ 
          5), 
i++, 
Print[
          TableForm[Table[s[ii, kk], {ii, 1, i}, {kk, 1, k}]]];]

If

f[a_, 
          x_] := (a x^4 + x^3 + x^2 + x + 1 == 
            0);
f[8, x]

solv = Solve[f[-4, x], {x}];
{x[1], x[2], x[3], x[4]} = x /. solv

Do[If[Element[x[k], Reals], Print["x[", k, "] ist reell"],  
        Print["x[", k, "] ist nicht reell"]], {k, 1, 4}]

\(Do[p = Random[]; \ 
If[p ≤ 0.2, 
        Print["p = ", 
          p, ", ==> 0 <= p ≤ 0.2"], 
If[
          p ≤ 0.4, 
          Print["p = ", 
            p, ", ==> 0.2 <= p < 0.4"], 
If[
            p ≤ 0.6, 
            Print["p = ", 
              p, ", ==> 0.4 ≤ p< 0.6"], 
If[
              p ≤ 0.8, 
              Print["p = ", 
                p, ", ==> 0.6 ≤ p< 0.8"], 
If[p ≤ 1.0, 
                Print["p = ", 
                  p, ", ==> 0.8 ≤ p< 1"]
]]]]], {k, 1, 8}]\)

Which

f[a_, 
          x_] := (a x^4 + x^3 + x^2 + x + 1 == 
            0);
solv = Solve[f[8, x], {x}];
{x[1], x[2], x[3], x[4]} = 
        Re[x] /. solv;
tab = {x[1], x[2], x[3], x[4]};
tab = Map[N, tab]

\(Which[
tab[\([1]\)] < \(-0.7\), \ 
      x = tab[\([1]\)], 
tab[\([2]\)] < \(-0.7\), \ 
      x = tab[\([2]\)], 
tab[\([3]\)] < \(-0.7\), \ 
      x = tab[\([3]\)], 
tab[\([4]\)] < \(-0.7\), \ 
      x = tab[\([4]\)], 
True, 
Print["Erstmals ist die Lösung ", \ 
        x, \ " kleiner als -0.7"]
]\)

Switch

f[a_, 
          x_] := (a x^4 + x^3 + x^2 + x + 1 == 
            0);
solv = Solve[f[8, x], {x}];
{x[1], x[2], x[3], x[4]} = 
        Re[x] /. solv;
tab = {x[1], x[2], x[3], x[4]};
tab = Map[N, tab]

a = 2;     
Switch[
      a, 
1,  x = tab[[1]]; 
      Print[x], 
2,  x = tab[[2]]; 
      Print[x], 
3,  x = tab[[3]]; 
      Print[x], 
4,  x = tab[[4]]; 
      Print[x], 
_, 
      Print["Keine Bedingung \
erfüllt"]
];

a = 4;    
\(\(Switch[a, 
1, \ x = tab[\([1]\)]; 
        Print[x], 
2, \ x = tab[\([2]\)]; 
        Print[x], 
3, \ x = tab[\([3]\)]; 
        Print[x], 
4, \ x = tab[\([4]\)]; 
        Print[x], 
_, 
        Print["Keine Bedingung erfüllt"]
];\)\)

a = 3;     
Switch[
      a, 
0,  x = tab[[1]], 
2,  
      x = tab[[2]], 
4,  
      x = tab[[3]], 
16,  
      x = tab[[4]], 
_, 
      Print["Keine Bedingung \
erfüllt"]
]