'Would you tell me, please, which way I ought to go from here?'
'That depends a good deal on where you want to get to,' said the Cat.
'I don't much care where —' said Alice.
'Then it doesn't matter which way you go,' said the Cat
'That depends a good deal on where you want to get to,' said the Cat.
'I don't much care where —' said Alice.
'Then it doesn't matter which way you go,' said the Cat
(Alice's Adventures in Wonderland by Lewis Carroll)
The next lesson “Decisions” introduced the conditional
operations. In other words, how the computer behaves when you give it
alternatives. It introduces the command line “if”.
Basically it works as the example below:
int x = -1;
if (x<0)
{
x=-x;
}
From the expression above we can infer that if the value of
x is inferior to 0, the computer should assign a negative value for x. In the
case, x equals -1. Therefore, -x will be 1.
The first exercise to check if the codification of the
conditionals was properly understood was complete a code based on the given table
of BMI (Body Mass Index).
For me, this exercise was not that difficult if you have
payed attention to the previous lessons.
The next step was to see how the codification works in a real environment.This activity was more exploratory, the result of the code was not required to be correctly gessed, but it was encouraged.
As can be seen, you should play with the results of a game and accorging to the score the program would show a different sentence regardint the result of the match.
After the presentation of the basic condition, it was presented the alternative code "else", in which you can give another path considering a different condition. Take a look at the basic example.
int n =
int n =
if(n<0)
{
x=-n;
}else{
x=n;
}
The first condition above is if n is a value under 0, the computer should assign the negative value of n. While the second condition means that in any other case the result of the code should be the same. In practical terms, of course.
The following exercise was a bit tricky, but not hard at all. The task was guess the results of the codes.
The following exercise was a bit tricky, but not hard at all. The task was guess the results of the codes.
The folowing 2 exercises, were variations of the past ones.
I would say that this unit was a bit easier compared to the previous two. Maybe it is because I'm becaming familiarized with this new language.
I'm so happy with my progress...
Até a próxima!
I would say that this unit was a bit easier compared to the previous two. Maybe it is because I'm becaming familiarized with this new language.
I'm so happy with my progress...
Até a próxima!



No comments :
Post a Comment