0

Soccer Robot C - Basic lessons - Not

We learned what logical expressions are (like "3<2"). Often we need to find opposite values. For example "3<2" is false, but "not 3<2" is opposite of false, therefore true. C++ has an operator for this purpose: "!", which is written before the belonging logical expression. First an example with animals:
  • Is the fox the same as rabbit? No, it is not. Hence, the following statement is not true, but false: "fox is rabbit".
  • How about a statement that has opposite truthfulness of "fox is rabbit"? Opposite of false is true, so that statement is true. In a pseudocode, we may write it as "not (fox is rabbit)", which is "not false", and that is "true".
Some C++ examples:
  • !3<2 evaluates true (opposite of false)
  • !2<3 evaluates false (opposite of true)

Task: guess the result.

What will the following program print?

void RobotSoccer::loop() {
	if (!-1<1)
		print("1");
	else
		print("2");
}