Title: Theory / Unimportant / CS / Programming / C++ / Manual / Norm / 09 statements;
Tags: syntactical_sugar declaration automatedNewLineAfterCommaSpace comment hasSeenConjDef notPartition todo_declaration

Question: Statements are used to
Answer: give the order of execution
Page: 225
Chapter: 9
Section: 1
Context: C++ standard

Name: Statements
Definition: declaration
Page: 226
Chapter: 9
Section: 2
Variables: All of
Context: C++
Definition2: expression_opt ;
Definition3: {statement-list_opt}
Intuition: Tells the program to do something.
Definition4: try {statement-list_opt} handler-list
Definition5: case constant-expression : statement
Definition6: default: statement
Definition7: break;
Definition8: continue;
Definition9: return expression_opt;
Definition10: goto identifier;
Definition11: identifier: statement
Definition12: selection-statement
Definition13: iteration-statement

Name: selection-statement
Definition: if statement
Page: 226, 228
Chapter: 9
Section: 2
Definition2: switch statement
Conjdef: All of

Name: iteration-statement
Definition: while and for statements
Page: 226
Chapter: 9
Section: 2

Name: statement-list
Definition: statement statement-list_opt
Page: 226
Chapter: 9
Section: 2
Context: C++'s Formal grammar

Name: condition
Definition: expression
Page: 226
Chapter: 9
Section: 2
Context: C++'s Formal grammar
Definition2: type-specifier declarator = expression
Conjdef: any of
Definition3: type-specifier declarator{ expression}
Etymology: what to use in if(), while() and middle of for

Name: handler-list
Definition: handler handler-list_opt
Page: 226
Chapter: 9
Section: 2
Context: C++'s formal grammar
Etymology: handle one possible kind of exception which may have occured during the run

Name: handler
Definition: catch (expression-declaration) {statement-lists_opt}
Page: 226
Chapter: 9
Section: 2

Name: A block
Definition: A (possibly empty) sequence of statements within ‘‘curly braces’’ (i.e., { and } )
Page: 227
Chapter: 9
Section: 2
Name2: A compound statement

Name: for-init-statement
Definition: a declaration
Page: 227
Chapter: 9
Section: 2
Context: C++'s formal grammar
Definition2: expression-statement
Conjdef: Either
Etymology: First part of a "for" loop

Name: for-init-declaration
Definition: declaration of a single unitialized variable
Page: 227
Chapter: 9
Section: 2
Context: C++'s formal grammar
Etymology: Content of a for each loop

Instruction: if (condition)
statement_then
else
statement_else
Page: 228
Effect: evaluate condition as bool. If value is true, execute statement_then, otherwise statement_else
Language: C++
Chapter: 9
Section: 4.1
Name: if statement

Instruction: if (condition) statement
Page: 229
Effect: if (condition) statement else {}
Language: C++
Chapter: 9
Section: 4.1

Instruction: switch(expr) {
  case value_1:
     expr_1;
  ...
  case value_n:
    expr_n;
  default:
    expr_default:
}
Page: 230
Effect: evaluate expr.
Let i such that the result of expr is value_i if such i exists.
Then execute
expr_i, expr_{i+1}, ..., expr_n, expr_default
otherwise execute expr_default
Language: C++
Chapter: 9
Section: 4.1
Variables: expr, value_1, ..., value_n, integral or enumeration type
Assuming: All value_i distinct
Intuition: expr_i's generally end with break, which ensure a single expr_i is actually executed

Name: fall-through
Definition: When the execution in a switch go from one case to the next one or to default
Page: 231
Chapter: 9
Section: 4.1
Context: C++
Intuition: generally because break/return was forgotten

Question: What is best practice with fall-through
Answer: comment they are intentional unless only the last case is non-empty
Page: 231
Chapter: 9
Section: 4.1
Context: C++

Question: What is the use of default in switch
Answer: throw an error if the value is not one expected or
Page: 231
Chapter: 9
Section: 4.1
Context: C++
Answer2: deal with the most common case, that does not require special treatment

Question: What is the use of avoiding default in switch
Answer: for an enum, it allow the compiler to warn of missing cases
Page: 231
Chapter: 9
Section: 4.1
Context: C++

Instruction: break
Page: 231
Effect: Go to the end of the inside-most loop or switch block
Language: C++
Chapter: 9
Section: 4.1

Question: What is the best practice with variable declared in switch statement
Answer: Put cases inside block, so that variables are not shared between cases
Page: 232
Chapter: 9
Section: 4.2.1
Context: C++

Instruction: type foo_1, foo_2, ..., foo_n;
Page: 227
Effect: same as
type foo_1;
type foo_2;
...,
type foo_n;
Language: C++
Chapter: 9
Section: 4.2.1

Instruction: type var_name;
Page: 227
Meaning: same as
type var_name {};
Language: C++
Chapter: 9
Section: 4.2.1
Context: inside a block
Name: Declaration statement
Extra: The declaration statement has the same syntax but different execution that declaration in struct or global namespace

Instruction: static type var_name;
Page: 227
Effect: same as type var_name; but initialization is done at run start and no destruction
Language: C++
Context: inside a block
Chapter: 9
Section: 4.2.1

Question: What is the point for declarations to return values
Answer: if (double d = comput) {
  foo(d)
}
Require a single computation of d and ensure it's scope is limited to if block
Page: 232
Chapter: 9
Section: 4.3
Context: C++

Instruction: while (condition) statement
Page: 236
Effect: execute condition. If it is true execute:
statement
while (condition) statement
Language: C++
Chapter: 9
Section: 5.3
Name: while-statement

Typ: a range<T>
Meaning: a type U with either:
* members T* begin() and T* end()
* where T* begin(const U&) and T* end(const U&) is defined
Page: 234
Language: C++
Chapter: 9
Section: 5.1
Intuition: for
t v
allow to iterate on v.begin() up to v.end() excluded

Instruction: for (t var : vars) statement
Page: 234
Effect: for (int i = 0; i < n; ++i) {
  t var = vars[i];
  statement
}
Language: C++
Chapter: 9
Section: 5.1
Variables: t vars[n]

Instruction: for (t p : vars) statement
Page: 234
Effect: for (t p = begin(vars); p != end(v); ++p) {
  statement
}
Language: C++
Chapter: 9
Section: 5.1
Variables: Some range<T> vars
Name: range-for

Instruction: for (
  init,
  condition,
  step
) statement
Page: 235
Effect: {
  init;
  while (condition) {
    statement
    step;
  }
}
Language: C++
Chapter: 9
Section: 5.2
Variables: Some range<T> vars
Name: for-statement

Question: in a loop statement, what mean an empty condition
Answer: true
Page: 237
Chapter: 9
Section: 5.5
Context: C++

Instruction: goto identifier
Page: 237
Effect: move the execution to statement labelled by identifier
Language: C++
Chapter: 9
Section: 5.5

Question: What are the acceptable use of goto?
Answer: to break of nested loop/switch
Page: 238
Chapter: 9
Section: 5.5
Context: C++
Answer2: in generated code

Language: C++
Abbreviation: // one-line comment
Instruction: /* some
multi
line
comment
*/
Other fields (not shown on cards):
Chapter: 9
Page: 239
Section: 5.5

Page: 230
Syntactic sugar: switch(expr) {
  case value_1:
     expr_1;
  ...
  case value_n:
    expr_n;
}
Implementation: same as
switch(expr) {
  case value_1:
     expr_1;
  ...
  case value_n:
    expr_n;
  default:
}
Language: C++
Section: 4.1
Variables: expr, value_1, ..., value_n, integral or enumeration type
Chapter: 9
Assuming: All value_i distinct

Page: 236
Syntactic sugar: do statement while (condition)
Implementation: statement
while(condition) statement
Language: C++
Section: 5.4
Chapter: 9
Name: do-statement