一.while循環java
while(布爾表達式)spa
{code
//代碼語句blog
}it
和C#一致for循環
二.do...while..循環class
do{循環
代碼語句 }while(布爾表達式)遍歷
在判斷條件以前已經執行的代碼語句,若是布爾表達式爲true,則重複執行代碼語句,直到布爾表達式爲false.static
若是布爾表達式爲false,則只執行一遍代碼語句.
三.for 循環
for(初始條件;循環條件;狀態改變)
{循環體,代碼語句}
和C#一致
四.遍歷(java加強for循環)
public class Test { public static void main(String args[]){ int [] numbers = {10, 20, 30, 40, 50}; for(int x : numbers ){ System.out.print( x ); System.out.print(","); } System.out.print("\n"); String [] names ={"James", "Larry", "Tom", "Lacy"}; for( String name : names ) { System.out.print( name ); System.out.print(","); } } }
輸出結果:
10,20,30,40,50,
James,Larry,Tom,Lacy,