流程控制與數組
阿新 • • 發佈:2017-09-15
break 循環 .com b- 分支結構 mage 技術 選擇性 cas
1 兩種基本流程控制結構。
分支結構:用於實現根據條件選擇性的執行某段代碼 if switch
循環結構:根據循環條件重復執行某段代碼 while , do while , for,
2 順序結構
從上到下逐行執行,中間沒有判斷,跳轉。
3 分支結構
if 使用布爾表達式或值作為條件經行分支控制,switch 語句用於對多個整形值經行匹配。
switch語句後的expression表達式的數據只能是byte short char int 4個整數類型,和枚舉類型,String類型,
如果省略了case後代碼塊的break,如果遇到匹配,則會一直執行下去,
char c = ‘c‘; switch (c) { case ‘a‘: System.out.println(‘a‘); System.out.println("mama"); break; case ‘b‘: System.out.println(‘b‘); System.out.println("mama"); break; case ‘c‘: System.View Codeout.println(‘c‘); System.out.println("mama"); break; case ‘d‘: System.out.println(‘d‘); System.out.println("mama"); break; default: break; } c mama
char c = ‘c‘; switch (c) {View Codecase ‘a‘: System.out.println(‘a‘); System.out.println("mama"); case ‘b‘: System.out.println(‘b‘); System.out.println("mama"); case ‘c‘: System.out.println(‘c‘); System.out.println("mama"); case ‘d‘: System.out.println(‘d‘); System.out.println("mama"); default: } c mama d mama
流程控制與數組