First, the loop structure (1): While structure while (condition) {statement block} If the condition is met, then execute once. Second, circular structure (2): Do-while structure Its logic is to execute the statement block first, and if the condition is met, continue to execute the statement block again, that is, if the Do-while statement is used, then the code in the statement block must be executed at least once.
III. cyclic structure (3) for structure
For(initial value; termination; step value)
Same as C language.
Four, logical operation:
"With"&& " or"| | "No"!
such as y!=0, conditions in C + + should be the if(! (y==0)) write this.
V.Continue and break:
The break statement's role in the loop is to jump out of the statement block. For loops, jumping out of a statement block is a permanent leap out of the loop, and the program continues to execute other code.
The meaning of continue is to skip The code after the continue in the statement block. After executing continue , do not jump out of the loop, but skip the code after him, directly to the judgment of the loop condition, if the conditions are met, it will go to the next cycle.
For i<11; of shaping data and the i<=10 , the effect is the same, but when writing a program to avoid less than equal to the appearance, so that the program can improve the speed of operation.
First, Function:
How do you declare a function that belongs to us?
We define the structure of our own function: The return value type function name (parameter table);
Such as:
void Add (int a,int b) is a return value type, it is special, it has no return value, and add means the name of the function is called Add, int A in parentheses, int b; is the parameter table. a , B, is a formal parameter and does not have an exact value and can only be passed through an argument.
#include <iostream>
using namespace Std;
void Add (int a,int b) {
functions that you define yourself
cout<<a+b<<endl; output a+b Results
Return
}
int main ()
{
Add (+); call your own built-in function
return 0;
}
Ii. separation of declarations and implementations
The code is as follows:
#include <iostream>
using namespace Std;
int add (int a,int b); function Declaration
int main ()
{
int x;
x = Add (n);
cout<<x<<endl;
return 0;
}
int add (int a,int b) {return a+b;} function Body
This function includes the function head and the function body, we will this function "existence" this information through the main function declaration before the function of the main function, I am a drop! The return value of this function is of type int , and we can declare an integer variable to accept the value returned by the function call.
Third, nested calls to functions:
In programming, a function can call another function, just like the F (G (X)) in mathematics .
#include <iostream>
using namespace Std;
int square (int l2);
int double_area (int L1);
int main () {
int l0=3;
Cout<<double_area (l0) <<endl;
return 0;
}
int square (int l2) {
return L2*L2;
}
int double_area (int L1) {
return 2*square (L1);
}
In this program, in addition to the main function, there is the square function (for the square of a number),Double_area (Used to find twice times the square area) two functions.
Clutter C + + learning