Valdymo struktūros 2

14
Valdymo struktūros 2

description

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 { - PowerPoint PPT Presentation

Transcript of Valdymo struktūros 2

Page 1: Valdymo struktūros 2

Valdymo struktūros 2

Page 2: Valdymo struktūros 2

While ciklas

while (expression) {// do stuff}orint x = 2;while(x == 2) {

System.out.println(x);++x;

}

Page 3: Valdymo struktūros 2

while (int x = 2) { }

Ar teisinga?

Page 4: Valdymo struktūros 2

int x = 1;

1 while (x) { }

2 while (x = 5)

3 while (x == 5) { }

4 while (true) { }

Page 5: Valdymo struktūros 2

Do ciklas

do {

System.out.println("Inside loop");

} while(false);

Page 6: Valdymo struktūros 2

For each

String [] sNums = {"one", "two", "three"};

for(String s : sNums) {

System.out.println(s);

}

Page 7: Valdymo struktūros 2

Break ir continueboolean 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}

Page 8: Valdymo struktūros 2

Ž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");

Page 9: Valdymo struktūros 2

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

Page 10: Valdymo struktūros 2

Išvardijimai

enum CoffeeSize { BIG, HUGE, OVERWHELMING };

Page 11: Valdymo struktūros 2

public class CoffeeTest1 {public static void main(String[] args) {

enum CoffeeSize { BIG, HUGE, OVERWHELMING } // WRONG! Cannot

// declare enums// in methodsCoffee drink = new Coffee();drink.size = CoffeeSize.BIG;

}}

Page 12: Valdymo struktūros 2

Išimtys

Page 13: Valdymo struktūros 2

Klaidų šaltiniai

• Kompiuteris

• JRE

• Vartotojo sukurta programa

Page 14: Valdymo struktūros 2