Learning By Doing Sequenz // Tu01.java import ch.aplu.turtle.*; class Tu01 { Tu01() { Turtle john = new Turtle(); john.forward(20); john.right(90); john.forward(20); john.left(90); john.forward(20); john.right(90); john.forward(20); john.left(90); } public static void main(String[] args) { new Tu01(); } } A n w e isu n g A n w e isu n g A n w e isu n g Learning By Doing Iteration: while-Struktur // Tu02.java, while-Struktur import ch.aplu.turtle.*; class Tu02 { Tu02() { Turtle john = new Turtle(); int i = 0; while (i < 5) { john.forward(20); john.right(90); john.forward(20); john.left(90); i++; } } public static void main(String[] args) { new Tu02(); } } nein B edin gung erfüllt? ja A nw eisung en while (Bedingung) { Anweisungen; } Learning By Doing do-while-Struktur // Tu03.java, do-while-Struktur import ch.aplu.turtle.*; A n w eisu n g e n class Tu03 { Tu03() { Turtle john = new Turtle(); B ed in g u n g erfü llt? int i = 0; do { john.forward(20); john.right(90); john.forward(20); john.left(90); i = i + 1; } while (i < 5); } public static void main(String[] args) { new Tu03(); } } ja n ein do { Anweisungen; } while (Bedingung) Learning By Doing for - Struktur // Tu04.java, for - Struktur i=0 import ch.aplu.turtle.*; class Tu04 { Tu04() { Turtle john = new Turtle(); nein i<5? ja for (int i = 0; i < 5; i++) { john.forward(20); john.right(90); john.forward(20); john.left(90); } Anweisungen i++ } } public static void main(String[] args) { new Tu04(); } for (Initialisierung; Bedingung; Wertänderung) { Anweisungen; } Learning By Doing Selektion: if – else - Struktur // Tu05.java, if - else - Struktur import ch.aplu.turtle.*; class Tu05 { Tu05() { Turtle john = new Turtle(); for (int i = 0; i < 100; i++) { john.forward(2); if (i < 50) john.left(3.6); else john.right(3.6); } } public static void main(String[] args) { new Tu05(); } } ja if-Block Bedingung erfüllt? nein else-Block if (Bedingung) { Anweisungen; } else { Alternativanweisungen; } Learning By Doing switch - Struktur // Tu06.java, switch - Struktur import ch.aplu.turtle.*; class Tu06 { Tu06() { Turtle john = new Turtle(); for (int i = 0; i < 4; i++) { switch(i) { case 0: john.forward(20); break; case 1: john.forward(40); break; default: john.forward(100); break; } john.left(90); } } public static void main(String[] args) { new Tu06(); } } Ausdruck a a == wert1? nein a == wert2? ja Block1 break; (ohne break) ja Block2 break; ja Block3 break; nein a == wert3? nein Defaultblock switch (ausdruck) { case wert1: Anweisungen; break; case wert2: Anweisungen; break; default: Anweisungen; break; } Nächste Anw.