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
- How are if, if-else, and if-else-if statements written in C?ComputerScienceOne · If, If-Else, If-Else-If Statements
- How do if, if-else, and if-else-if statements work in PHP?ComputerScienceOne · If, If-Else, If-Else-If Statements
- What are examples of if, if-else, and if-else-if statements in Java?ComputerScienceOne · If, If-Else, If-Else-If Statements
- How is a basic while loop structured in Java?ComputerScienceOne · While Loops
- How are while loops structured and styled in PHP?ComputerScienceOne · While Loops
- How can conditionals calculate tax brackets, credits, and total tax?ComputerScienceOne · Quadratic Roots Revisited
- How can conditionals validate logarithm inputs and handle errors?ComputerScienceOne · Life & Taxes
- How are strings, statements, and code blocks written in PHP?ComputerScienceOne · Basic Syntax Rules