Concept
What curly-bracket convention should be used with conditional statements?
ComputerScienceOne / Computing a Logarithm
"Another convention that we’ve used in our code is where we have placed the curly brackets. First, if a conditional statement is bound to only one statement, the curly brackets are not necessary. However, it is best practice to include them even if they are not necessary and we’ll follow this convention. Second, the opening curly bracket is on the same line as the conditional statement while the closing curly bracket is indented to the same level as the start of the conditional statement. Moreover, the code inside the code block is indented. If there were more statements in the block, they would have all been at the same indentation level."
Related Ideas
- Why does an extra semicolon make the conditional statement ineffective?ComputerScienceOne · Computing a Logarithm
- How can the logarithm of a number be computed in an arbitrary base?ComputerScienceOne · Computing a Logarithm
- How can conditionals validate logarithm inputs and handle errors?ComputerScienceOne · Life & Taxes
- How can conditionals validate input for a logarithm calculator?ComputerScienceOne · Quadratic Roots Revisited
- How can conditionals and the change of base formula validate logarithm input in PHP?ComputerScienceOne · Life & Taxes