Knowledge check: Conditional statements: Controlling program flow
Practice Assignment
1. What is the output of the following code:
I am good I am average
(No output)
I am average
I am good
2. True or False: The following code will execute correctly:
True
False
3. What are the advantages of logical operators over nested if and else statements? Select all that apply.
Reduction of complexity by having concise and readable code
More in tune with the human thought process
Minimizing unnecessary evaluations
Helps repetition of code
4. Choose the correct statements. Select all that apply.
A switch statement can be used to compare values using the comparison operators like >, < , >= and so on.
A switch statement makes the code easier and more concise when multiple if equality checking is required.
A default statement is compulsory in a switch case.
A switch statement is equivalent to using multiple if statements. We can use multiple if statements in place of a switch, but a switch statement helps us reduce code.
5. Review the code block below and choose the correct display that you would get:
A B C D
B
A
A C
Knowledge check: Iterative structures: For and while loops
Practice Assignment
6. Consider the following code and choose the correct output.
“Hello” is displayed seven times and loopVar = 1.
None of the options.
“Hello” is displayed six times, and loopVar = 1.
“Hello” is displayed seven times, and loopVar = 0.
7. True or False: The output of the following code block returns Value : 2 Value : 5.
False
True
8. Explore the following code block. Select all that apply.
The loop will execute five times.
The while loop executes until a condition is met.
The println() method creates line breaks.
The output displays an error.
9. Consider the following code and choose the correct output.
The loop displays: The number: 12 gives the condition (loopVar <10) is true.
The output indicates The number: 12 gives the condition (loopVar <10) as: false.
The output displays an error.
The condition loopVar < 10 is false, and the loop stops.
10. Toni is selling ice cream, but he is running low on stock. Therefore, Toni instructs SideKick to buy ice cream containers while he is manning the store. SideKick can only carry three containers at a time. Explore the following code block and choose the correct answer.
No output
3 6
4 8 12
Syntax Error.
Module quiz: Control flow: Statements and loops
Graded Assignment
11. Select the correct output for the following code snippet:
No output
A
None of the options
Compilation error
12. Select the correct output for the following code:
true
Compilation error
!A
false
13. Select all the correct outputs for the following code snippet:
##
@@
Contains irrelevant code.
**
14. Select the correct output for the following code:
##
Compilation error
No display.
None of the options
15. Select the correct output for the following code:
No output
Compilation error
##
None of the options
16. Select all the values that would be displayed for the following code:
July
Invalid month for playing with snow in our zone
December
November
17. Select all the correct outputs for the following code:
10 9 8 7 6 5 4 3 2 1 0
10 8 6 4 2 0 -2
No output
10 8 6 4 2 0
18. Select the correct output for the following code:
None of the options
Compilation error
Value = 1 Value = 2 Value = 3
Infinite loop
19. Select the correct output for the following code:
None of the options
1 2 3 4
1 2 3 4 5
1 2 3
20. Select the correct output for the following code: