Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------- Tasks for if ---------
- //1. just general
- one girl has a mother, a father, a sister and a brother.
- each person has sex and two parents.
- how many ifs should we use to find out relationship between the girl and her random relative?
- answer: 3
- example:
- if (me.F = he.F)
- if (he.male) "brother"
- else "sister"
- else if (me.F = he) "father"
- else "mother"
- (may be expanded to other relatives, like granny, aunt and so on... It becomes much more interesting then)
- //2. Theory about braces
- Choose all that apply.
- when we want to return the if result as an expression, we must omit curly braces. (-)
- when we want to use if without else branch we must include curly braces. (-)
- we must use curly braces if we have several statements inside if or else branch. (+)
- when we use if not as an expression we must include curly braces. (-)
- we can't omit round brackets around boolean condition if we use if as an expression (+)
- //3. More theory:
- Choose all that apply.
- the if-else-if branch can omit else branch. (+)
- we can use if-else-if-else branch as an expression (+)
- we can not nest non expressional style ifs inside expressional style one (-)
- all expression style if branches must return the same type. (-)
- expression style if must have else branch (+)
- //4. some code exapmle
- What will be the result of this code
- println(if (if (false) true else false) if (true) { true } else false)
- true(+)
- false(-)
- It won't compile because of the first if(+)
- It won't compile because of the second if(-)
- It won't compile because of the third if(-)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement