0%

day16

logic Operators

&& and

|| or

! not

Logical Expressions:
expression1 && expression2 is true if and only if both expressions are true. expression1 || expression2 is true if either one or both expressions are true. !expression is true if the expression is false, and vice versa.

if #include<ios646.h>,then you can use and as &&,or as || not as ! .

?

x = (y < 0) ? -y : y; equal

1
2
3
4
if(y < 0)
x = -y;
else:
x = y;

max = (a > b) ? a : b; equal

1
2
3
4
if(a > b)
max = a;
else:
max = b;

continue and break

continue

When encountered, it causes the rest of an iteration to be skipped and the next iteration to be started. If the continue statement is inside nested structures, it affects only the innermost structure containing it.

break

A break statement in a loop causes the program to break free of the loop that encloses it and to proceed to the next stage of the program. If the break statement is inside nested loops, it affects only the innermost loop containing it.

switch

1
2
3
4
5
6
7
8
9
10
switch (ch)
{
case 'a':
printf("argali, a wild sheep of Asia\n");
printf("argali, a wild sheep of Asia\n");
case 'b':
printf("babirusa, a wild pig of Malay\n");
default:
printf("That's a stumper!\n");
}

equal

1
2
3
4
5
6
7
8
9
if(ch == a)
{
printf("argali, a wild sheep of Asia\n");
printf("argali, a wild sheep of Asia\n");
}
else if(ch == b)
printf("babirusa, a wild pig of Malay\n");
else:
printf("That's a stumper!\n");
------------- The end -------------

Welcome to my other publishing channels