This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Which of the following statements is true about showing/removing the curly braces for code blocks associated with an if statement?
if
The curly braces can't be removed from the code block for else if and else statements.
else if
else
If the curly braces are removed from the code blocks of an if-elseif-else, the white space must also be removed.
if-elseif-else
Always choose a style that improves readability.
A developer writes some code that includes an if statement code block. They initialize a first integer variable to a value of 1 above (outside) of the code block. The Boolean expression for the if statement code block evaluates to true if the first integer variable has a value greater than 0. The first code line inside of the code block is used to initialize a second integer variable to a value of 8. The second code line inside the code block is used to assign the sum of the two integer values to the first variable. The first code line after the code block is used to display the value of the first integer variable. What is the result when the code is executed?
true
No error is generated and the integer value 9 is displayed.
No error is generated and the integer value 1 is displayed.
An error is generated because the first variable is not in-scope after the code block.
A developer writes some code that includes an if statement code block. They initialize a first integer variable to a value of 5 above (outside) of the code block. The Boolean expression for the if statement code block evaluates to true if the first integer variable has a value greater than 0. The first code line inside of the code block is used to initialize a second integer variable to a value of 6. The first code line after the code block is used to add the second integer value to the value of the first integer. The second code line after the code block is used to display the value of the first integer. What is the result when they run the code?
No error is generated and the integer value 11 is displayed.
An error is generated by the code line used to display the integer value.
A build error is generated by the code line used to sum the two integers.
You must answer all questions before checking your work.
Continue
Was this page helpful?