Chapter 1 Statements
(I) simple statements
Explain expression Statement (expression_r Statement)
A semicolon is added to an expression, which causes the expression to be evaluated during execution.
Statement (null Statement)
It is composed of only one Semicolon. It is used when a statement is required but not logically required.
Explain statement
Used to declare or define objects or classes
(Ii) compound statement
Compound statement is also known as block. It is a sequence of (possibly null) Statements enclosed by a pair of curly braces {}.
Statement is usually used when syntax rules require a single statement but the program logic requires multiple statements.
The primary block indicates a scope, and the name introduced in the block can only be accessed within it.
(Iii) control flow statements
Note: variables defined as part of the statement control structure are only visible in this statement.
Condition Branch Structure
(1)IfStatement
AboutElse-IfAmbiguity of matching:
ElseMatched to the last occurrence of unmatched
If
(2)SwitchStatement
①SwitchAfter calculating the value of the expression, jump to the matching label (if there is no matching, jump
Default), And continues from this point,
UntilSwitchThe statement ends or encounters
BreakStatement
②SwitchThe result of the solution expression must be an integer.
CaseThe value of a label must also be an integer constant expression.
③SwitchInternal variable definition
· You canSwitchDefine and initialize variables in the solved expression
· To avoid skipping variable definitions, only variables can be defined after the last label
· You can also introduce block statements to define variables.
Lifecycle Loop
(1)WhileStatement
Note: The variables defined in the loop condition must go through the creation and revocation processes for each loop.
(2)ForLoop statement
Note: The initialization statements, cycle conditions, and expressions in the statement header can be omitted.
If the cycle condition is omitted, the value is always true.
(3)Do
WhileStatement
Note: variables cannot be defined in cyclic conditions.
BytesBreakStatement
Used to end the nearest peripheralWhile,
Do While,
ForOr
SwitchStatement, and continue to execute
BytesContinueStatement
Cause the most recent peripheral loop Statement (For,
While,Do
While) The ongoing iteration ends ahead of schedule.
BytesGotoStatement
(1)GotoThe statement provides an unconditional jump inside the function to implement
GotoThe statement jumps to a labeled statement in the same function.
Avoid using it unless there is sufficient reasonGotoStatement
(2) provide an identifier and a colon Before any statement to obtain a labeled Statement (labeled Statement)
Identifier: Statement
UseGotoStatement jump to this statement:
GotoIdentifier;
Because the identifier can only be usedGotoSo it can be the same as other types of identifiers (such as variable names)
(3)GotoStatements cannot jump forward across variable definition statements
If you do needGotoVariables must be defined in the block if they are defined between the target location and the target location.
BytesTry,
CatchStatement andThrowExpression
Used for Exception Handling
BytesReturnStatement
Used to end the current function and return the function to be called for execution.
Zookeeper uses a pre-processor for debugging
Using ndebug preprocessing variables to implement conditional debugging code (similar to header file protection characters)
# Ifndef ndebug
# Define ndebug
// Debug the code
# Endif
If ndebug is defined, debugging code is not executed.
Prepare ndebug preprocessing variables and assert preprocessing macros
Defined in the header file cassert, it is often used to check the impossible situation, in the form
Assert (expression)
If the expression returns false, assert outputs Information and terminates the program.
If ndebug preprocessing variables are defined, assert will be ignored and will not generate any runtime price
The compaction Preprocessor defines four constants that are useful during debugging.
_ File name
_ Line _ current row number
_ Time _ Compilation Time
_ Date _ compile date