A solution which does not prepare
for the next round with some
increased insight is hardly a
solution at all.
(Richard Hamming)
The fourth module, Conditional Expressions and Statements,was a bit complex. Actually it is related to the fact that the conditional expressions were very tricky. But once I understood the logic behind the statements, things got more natural. What does not means that it was completely natural.
Firstly, was introduced the Ternary Operator, that in simple terms is a simplification of the previous chapter. The basic structure of the statements is the following sentence:
b?e1:e2
The terms of the expression are:
b, the bolean value;
e1, the expression in the case of the bolean value be TRUE, and;
e2, the expression to be used in the FALSE case.
See below an example of how do this statement works.
int n=-1
int x= ?
n<0 ? x=-n:x=n;
The goal of the statment in the given example is to give the ablsolute values of the numbers. so if the number is negative the result would be the positive equivalent value while if the value of n is positive, the value assigned for x will be the proper number.
In the example the result is 1
The second part of the lesson presents how the conditionals works in compairson with the conditionals presented on the previous lesson. I.e.:
Observe the statement:
if (b) {x=m;}
else {x=n;}
Note that it is equivalent to the following conditional expression:
x=
(b) ? m:n
Then, there was the exercises.
The first exercise consisted in the simplification of the expressions.
Later, you were supposed to determine the equivalent boolean function according to the statements:
The next exercise was very tricky. Since each blank space only had 2 possible answers, true or false, it took a while to understand the reason why the correct answers were correct. Precisely it took 2 lines.
Finally, there were the exercises in the programming environment. The first one consisted in guess the result of the code and the second in make modifications on the code in order to make it work properly. The code is supposed to deliver the number of days of each month considering the leap year. The activity was not that hard and apparently there were several ways to solve it.
How do I feel after this unity?
Tired and a bit afraid about what's next!
Até a próxima!!
b?e1:e2
The terms of the expression are:
b, the bolean value;
e1, the expression in the case of the bolean value be TRUE, and;
e2, the expression to be used in the FALSE case.
See below an example of how do this statement works.
int n=-1
int x= ?
n<0 ? x=-n:x=n;
The goal of the statment in the given example is to give the ablsolute values of the numbers. so if the number is negative the result would be the positive equivalent value while if the value of n is positive, the value assigned for x will be the proper number.
In the example the result is 1
The second part of the lesson presents how the conditionals works in compairson with the conditionals presented on the previous lesson. I.e.:
Observe the statement:
if (b) {x=m;}
else {x=n;}
Note that it is equivalent to the following conditional expression:
x=
(b) ? m:n
Then, there was the exercises.
The first exercise consisted in the simplification of the expressions.
The next exercise was very tricky. Since each blank space only had 2 possible answers, true or false, it took a while to understand the reason why the correct answers were correct. Precisely it took 2 lines.
How do I feel after this unity?
Tired and a bit afraid about what's next!
Até a próxima!!




No comments :
Post a Comment