0為false 1為true
for的彙編**
for (int i = 0; i < 5; i++){}
00401048 mov dword ptr [ebp-4],0 //dword ptr 表示i為整型,ebp-4偏移到變數i
0040104f jmp forgoto+2ah (0040105a) //goto偏移2a位到0040105a
00401051 mov eax,dword ptr [ebp-4] //eax = i
00401054 add eax,1 //eax++
00401057 mov dword ptr [ebp-4],eax //i = eax
0040105a cmp dword ptr [ebp-4],5 //比較整型i和5
0040105e jge forgoto+32h (00401062) //為偶則執行goto偏移32
00401060 jmp forgoto+21h (00401051) //goto偏移21
c語言goto
goto mov;
jmp:
}while的彙編**
int i = 0;
00401098 mov dword ptr [ebp-4],0
while (i < 5)
0040109f cmp dword ptr [ebp-4],5
004010a3 jge whilegoto+30h (004010b0)
004010ae jmp whilegoto+1fh (0040109f)
c語言goto
i++;
goto cmp
jmp:
}do while彙編**
int i = 0;
004010e8 mov dword ptr [ebp-4],0
do while (i < 5);
004010f8 cmp dword ptr [ebp-4],5
004010fc jl dowhilegoto+1fh (004010ef) //小於則jmp
c語言goto
}總結do while是效率最高的.
C 05 goto模擬迴圈及函式的底層原理
int n 1 int nsum 0 dowhile n 100 do begin nsum nsum n n if n 100 int n 1 int nsum 0 while n 100 while begin if n 100 nsum nsum n n goto while begin wh...
不用goto語句跳出多重迴圈
一直很喜歡用goto,它很靈活,但是教材 網上,都說goto不好.一次性跳出多重迴圈不但能保證某些情況下的資料正確運算,而且顯著提高執行效率,跳出多重迴圈不用goto怎麼辦呢.周五晚上正好需要處理乙個多重迴圈的問題,想到呼叫函式執行運算,然後return。使用goto方式 static void m...
PHP 分支與迴圈和goto
分支與迴圈 1 if中的判斷條件 is bool 判斷是否是布林型 is int is integer 和is long 判斷是否為整型。is float is double 和is real 判斷是否為浮點型 is string 判斷是否為字串 is array 判斷是否為陣列 is object...