140 likes | 238 Views
Valdymo struktūros 2. While ciklas. while (expression) { // do stuff } or int x = 2; while(x == 2) { System.out.println(x); ++x; }. while (int x = 2) { } Ar teisinga?. int x = 1; 1 while (x) { } 2 while (x = 5) 3 while (x == 5) { } 4 while (true) { }. Do ciklas. do {
E N D
While ciklas while (expression) { // do stuff } or int x = 2; while(x == 2) { System.out.println(x); ++x; }
while (int x = 2) { } Ar teisinga?
int x = 1; 1 while (x) { } 2 while (x = 5) 3 while (x == 5) { } 4 while (true) { }
Do ciklas do { System.out.println("Inside loop"); } while(false);
For each String [] sNums = {"one", "two", "three"}; for(String s : sNums) { System.out.println(s); }
Break ir continue boolean problem = true; while (true) { if (problem) { System.out.println("There was a problem"); break; } } while (!EOF) { //read a field from a file if (wrongField) { continue; // move to the next field in the file } // otherwise do other stuff with the field }
Žymės boolean isTrue = true; outer: for(int i=0; i<5; i++) { while (isTrue) { System.out.println(“1"); break outer; } System.out.println(“2"); } System.out.println(“3");
outer: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { System.out.println(“1"); continue outer; } System.out.println(“2"); } System.out.println(“3");
Išvardijimai enum CoffeeSize { BIG, HUGE, OVERWHELMING };
public class CoffeeTest1 { public static void main(String[] args) { enum CoffeeSize { BIG, HUGE, OVERWHELMING } // WRONG! Cannot // declare enums // in methods Coffee drink = new Coffee(); drink.size = CoffeeSize.BIG; } }
Klaidų šaltiniai • Kompiuteris • JRE • Vartotojo sukurta programa