#include <iostream>
#include <string>
5.1 for循环
void forDemo ( ) {
using namespace std;
for ( int i = 0 ; i < 10 ; i++ ) {
cout << i+ 1 << " never give up" << endl;
} ;
}
5.1.1. for循环的组成部分
void partOfFor ( ) {
using namespace std;
cout
<< "for循环的组成部分:\n"
<< "for (initialization; test-expression; update-expression){\n body\n}\n"
<< "1.设置初始值\n"
<< "2.执行测试\n"
<< "3.执行循环操作\n"
<< "4.更新用于测试的值" << endl;
}
void backwords ( ) {
using namespace std;
int num; cout << "please input the number " ;
cin >> num; cout << "you input number is " << num << endl;
for ( num; num > 0 ; num-- ) {
cout << "num = " << num << "\n" ;
}
cout. setf ( ios_base:: boolalpha) ;
cout << ( 1 < 3 ) << endl;
cout << ( 2 > 3 ) << "\n" ;
}
5.1.2. 回到for循环
void factorial ( ) {
using namespace std;
const int Max = 16 ;
long long archive[ Max] ;
archive[ 0 ] = archive[ 1 ] = 1ll ;
for ( int i = 2 ; i < Max; i++ ) {
archive[ i] = i * archive[ i- 1 ] ;
}
for ( int j = 0 ; j < Max; j++ ) {
cout << j << " != " << archive[ j] << endl;
}
}
5.1.3. 修改步长
void wideChange ( ) {
using namespace std;
for ( int i = 0 ; i < 100 ; i+ = 14 )
{
cout << "i = " << ( i+ 1 ) << endl;
}
}
5.1.4. 使用for循环访问字符串
void visitString ( ) {
using namespace std;
string str;
cin >> str;
cout << str. size ( ) << endl;
for ( int i = str. size ( ) - 1 ; i >= 0 ; i-- ) {
cou