Skip to content

Latest commit

 

History

History
98 lines (58 loc) · 1.44 KB

CppIf.md

File metadata and controls

98 lines (58 loc) · 1.44 KB

 

 

 

 

 

 

if is a keyword to allow conditional program flow.

 

A Yoda condition is a type of if-statement.

 

 

 

 

 

 

 

 

 

 

 

  • Prefer a switch-statement to an if-statement when there is a choice [1]
  • Placing a semicolon immediately after the right parenthesis after the condition in an if statement is often a logic error, although not a syntax error [2]

 

 

 

 

 

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 9.8. Advice, page 240: '[2] Prefer a switch-statement to an if-statement when there is a choice'
  2. Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 2.6, Common Programming Error 2.4. page 34: 'Placing a semicolon immediately after the right parenthesis after the condition in an if statement is often a logic error (although not a syntax error)'