Bifalgorithm post · Computer science one · Computing a Logarithm

What curly-bracket convention should be used with conditional statements?

What curly-bracket convention should be used with conditional statements? (Computer science one · Computing a Logarithm) — "Another convention that we’ve used…

Ideas in this flowchart

  • Convention for placing curly brackets in code
  • Curly brackets are not necessary when a conditional statement contains only one statement.
  • It is best practice to include curly brackets even when they are optional.
  • The opening curly bracket is placed on the same line as the conditional statement.
  • The closing curly bracket is indented to the same level as the start of the conditional statement.
  • Code inside the code block is indented.
  • Multiple statements in the block are placed at the same indentation level.
Feed/

What curly-bracket convention should be used with conditional statements?

No cover

Channel

Computer science one

1 page

"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."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.