遍匈 / Java縮殻 /

Java儉桟陣崙

<貧匯准 和匯准>
嗤扮昨厘断俶勣謹肝峇佩匯倖囂鞘翠?宸扮昨俶勣聞喘儉桟潤更。
Java慌嗤眉嶽儉桟潤更?泌和?
  • while儉桟
  • do…while儉桟
  • for儉桟
Java 5嶄哈秘阻匯嶽麼勣喘噐方怏議奐膿侏for儉桟。

while儉桟?

while儉桟麼勣聞喘万峇佩飛孤肝揖匯販暦。

喘隈?

while(下櫛燕器塀)
{
 //囂鞘
}
峪勣下櫛燕器塀葎true?儉桟悶氏匯岷峇佩和肇。

箭徨?

public class Test {
 public static void main(String args[]) {
 int x = 10;
 while( x < 20 ) {
 System.out.print("value of x : " + x );
 x++;
 System.out.print("
");
 }
 }
}
塰佩潤惚泌和?
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19

do…while儉桟?

do…while儉桟才while儉桟屢貌?音揖議頁?do…while儉桟崛富氏峇佩匯肝。

喘隈?

do {
 //囂鞘
}while(下櫛燕器塀);

廣吭?下櫛燕器塀壓儉桟悶議朔中?侭參囂鞘翠壓殊霞下櫛燕器塀岻念厮将峇佩阻。
泌惚下櫛燕器塀議峙葎true?夸囂鞘翠匯岷峇佩?岷欺下櫛燕器塀議峙葎false。

箭徨?

public class Test {
 public static void main(String args[]){
 int x = 10;
 do{
 System.out.print("value of x : " + x );
 x++;
 System.out.print("
");
 }while( x < 20 );
 }
}
塰佩潤惚泌和?
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19

for儉桟?

for儉桟峇佩議肝方頁壓峇佩念祥鳩協議。囂隈鯉塀泌和“

喘隈?

for(兜兵晒; 下櫛燕器塀; 厚仟) {
 //囂鞘
}
購噐for儉桟嗤參和叱泣傍苧?
  • 恷枠峇佩兜兵晒化帶。辛參蕗苧旺兜兵晒匯倖賜謹倖儉桟陣崙延楚?匆辛參頁腎囂鞘。
  • 隼朔?殊霞下櫛燕器塀議峙。泌惚葎true?儉桟悶瓜峇佩。泌惚葎false?儉桟嶮峭?蝕兵峇佩儉桟悶朔中議囂鞘。
  • 峇佩匯肝儉桟朔?厚仟儉桟陣崙延楚。
  • 壅肝殊霞下櫛燕器塀。儉桟峇佩貧中議狛殻。

箭徨?

public class Test {
 public static void main(String args[]) {
 for(int x = 10; x < 20; x = x+1) {
 System.out.print("value of x : " + x );
 System.out.print("
");
 }
 }
}
塰佩潤惚泌和?
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19

Java嶄奐膿議for儉桟?

Java 5哈秘阻匯嶽麼勣喘噐方怏議奐膿侏for儉桟。

喘隈?

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("
");
 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,

break購囚忖?

break麼勣喘壓儉桟囂鞘賜宀switch囂鞘嶄?喘栖柳竃屁倖囂鞘翠。
break柳竃恷戦蚊議儉桟?旺拝写偬峇佩乎儉桟和中議囂鞘。

喘隈?

break議喘隈載酒汽?祥頁儉桟潤更嶄議匯訳囂鞘?
break;

箭徨?

public class Test {
 public static void main(String args[]) {
 int [] numbers = {10, 20, 30, 40, 50};
 for(int x : numbers ) {
 if( x == 30 ) {
 break;
 }
 System.out.print( x );
 System.out.print("
");
 }
 }
}
塰佩潤惚泌和?
10
20

continue購囚忖?

continue癖喘噐販採儉桟陣崙潤更嶄。恬喘頁斑殻會羨震柳廬欺和匯肝儉桟議亨旗。
壓for儉桟嶄?continue囂鞘聞殻會羨軸柳廬欺厚仟囂鞘。
壓while賜宀do…while儉桟嶄?殻會羨軸柳廬欺下櫛燕器塀議登僅囂鞘。

喘隈?

continue祥頁儉桟悶嶄匯訳酒汽議囂鞘?
continue;

箭徨?

public class Test {
 public static void main(String args[]) {
 int [] numbers = {10, 20, 30, 40, 50};
 for(int x : numbers ) {
 if( x == 30 ) {
 continue;
 }
 System.out.print( x );
 System.out.print("
");
 }
 }
}
塰佩潤惚泌和?
10 20 40 50

和匯准勣讐議坪否?
和匯准麼勣冥網Java囂冱嶄議蛍屶陣崙潤更。
<貧匯准 和匯准>

AltStyle によって変換されたページ (->オリジナル) /