1 && 1 true && true |
1 true |
1 && 0 true && false |
0 false |
0 && 1 false && true |
0 false |
0 && 0 false && false |
0 false |
1 || 1 true || true |
1 true |
1 || 0 true || false |
1 true |
0 || 1 false || true |
1 true |
0 || 0 false || false |
0 false |
~0 ~ false |
1 true |
~1 ~ true |
0 false |
3 > 1 | true - 1 |
-2 > -6 | true - 1 |
4 > 4 | false - 0 |
3 < 9 | true - 1 |
-4 < 0 | true - 1 |
6 < 2 | false - 0 |
2 >= 1 | true - 1 |
5 >= 5 | true - 1 |
1 >= 3 | false - 0 |
7 <= 10 | true - 1 |
6 <= 6 | true - 1 |
-1 <= -3 | false - 0 |
1 == 1 | true - 1 |
-3 == -3 | true - 1 |
2 == -1 | false - 0 |
3 ~= 4 | true - 1 |
0 ~= 2 | true - 1 |
6 ~= 6 | false - 0 |
-3 < x < 5 while x > -3 && x < 5 |
x >= -5, x not equal to 0 while x >= -5 && x ~= 0 |
x odd but not negative while mod(x,2) == 1 && x >= 0 |
x even or negative while ~mod(x,2) || x < 0 |
x is 'yes' or 'maybe' while x == 'yes' || x == 'maybe' |
x is not 'no' and not 'maybe' while x ~= 'no' && x ~= 'maybe' |
x is odd and not 3 OR x is even and positive while (mod(x,2) == 1 && x ~= 3) || (~mod(x,2) && x > 0) |
x is 'red' or 'blue' or 'green' AND x is 'orange' or 'yellow' or 'pink' while (x == 'red' || x == 'blue' || x == 'green') && (x == 'orange' || x == 'yellow' || x == 'pink') |
A = randi(15,5) | |
B = A < 9 | |
A(B) | |
A(A<9 && A>2) | |
A(A<9 && ~mod(A,2)) | |
A(A<9 && ~mod(A,2) & A~=2) | |
A(A>10) = 10 |
while expression statements end |
n = 4; f = n; while n > 1 n = n - 1; f = f * n; end |
n = 4 f = 4 4 > 1 is true -- loop continues n = n - 1 = 4 - 1 = 3 f = f * n = 4 * 3 = 12 |
n = 3 f = 12 3 > 1 is true -- loop continues n = n - 1 = 3 - 1 = 2 f = f * n = 12 * 2 = 24 |
n = 2 f = 24 2 > 1 is true -- loop continues n = n - 1 = 2 - 1 = 1 f = f * n = 24 * 1 = 24 |
n = 1 f = 24 1 > 1 is false -- loop breaks |
limit = 0.8; s = 0; while 1 tmp = rand; if tmp > limit break end s = s + tmp; end |
A = zeros(1,9); n = 10; while n > 0 n = n - 1; if n == 3 continue; end A(1,i) = i; end A |
% brownEggs = 1 % whiteEggs = 2 % blueEggs = 3 % goldEggs = 4 A = randi(4,10) n = 10; while n > 0 m = 10; while m > 0 if A(m,n) == 4 A(m,n) = 1000; end m = m - 1; end n = n - 1; end A |
n = 10; start = n; f = n; while n > 1 n = n-1; f = f*n; end fprintf('%d! = %d',start,f); |
n = .5; m = 0; while n < .95 && n > .05 n = rand; m = m + 1; end fprintf('You made it through the loop %d times\n',m) |
m = .5; n = .5; hold on while (m < .9 && m > .1) || (n < .9 && n > .1) n = rand; m = rand; plot(m,n,'*r') plot(n,m,'*b') end |
m = .5; n = .5; hold on while (m < .9 && m > .1) || (n < .9 && n > .1) n = rand; m = rand; plot(m,n,'*c') plot(n,m,'*g') end |
"I know the human being and fish can co-exist peacefully." |
"Machismo gracias" - Thanking someone
while campaigning for re-election as Vice President
|