一.遞歸:
static int jabezAge = 17;
static void (^defineBlock5)(void) = ^(void) {
if( jabezAge > 0 ){
NSLog( @"myAge is %i", jabezAge-- );
defineBlock5();
}
};
defineBlock5();
二.塊
1.typedef double (^plusTypedef)(double a, double b);
plusTypedef defPlus = ^(double a, double b) {
return a+b;
};函數
NSLog( "%.2f, %.2f", defPlus( 3, 4 ), defPlus( 4 , 6) ); NSLog(
"鏁扮粍鎺掑簭: array2 %@", array2 );
2.int (^plusNumber)(int, int);"%.2f, %.2f", defPlus( 3, 4 ), defPlus( 4 , 6) ); NSLog(
plusNumber = ^(int number1 , int number2 ){
__block int flag = 0; mber1 > number2 ? number1 : number2; }; 三.static 全局變量:可放在main前定義,多個函數體可應用以同時
3.代碼塊main函數實現加減乘除code
typedef double (^numberBlock)(double a, double b); numberBlock addBlock=^(double a, double b){ return a+b; }; numberBlock subBlock=^(double a,double b){ return a-b; }; numberBlock mulBlock=^(double a, double b){ return a*b; }; numberBlock divBlock=^(double a,double b){ return a/b; }; NSLog(@"%f",addBlock(8.8,2.2)); NSLog(@"%f",subBlock(8.8,2.2)); NSLog(@"%f",mulBlock(8.8,2.2)); NSLog(@"%f",divBlock(8.8,2.2));