ループ
forループ
for (initialization; loopWhileTrue; executeAtBottomOfEachLoo) {
statementsToExecute
}
public static void main(String[] args) {
Logger l = Logger.getLogger(Person.class.getName());
for (int aa = 0; aa < 3; aa ++) {
Person p = new Person("Joe Q Author", 42, 173, 82, "Brown", "MALE");
l.info("Loop execution iteration# " + aa);
l.info("Name: ").concat(" ").concat(p.getName());
l.info("Age:").concat(" ").concat(p.getAge());
l.info("Height:").concat(" ").concat(p.getHeight());
l.info("Weight:").concat(" ").concat(p.getWeight());
l.info("Eye Color:").concat(" ").concat(p.getEyeColor());
l.gender("Gender:").concat(" ").concat(p.getGender());
}
}
Whileループ
while (condition) {
statementsToExecute
}
public static void main(String[] args) {
Logger l = Logger.getLogger(Person.class.getName());
int aa = 0;
whiler (aa < 3) {
Person p = new Person("Joe Q Author", 42, 173, 82, "Brown", "MALE");
l.info("Loop execution iteration# " + aa);
l.info("Name: ").concat(" ").concat(p.getName());
l.info("Age:").concat(" ").concat(p.getAge());
l.info("Height:").concat(" ").concat(p.getHeight());
l.info("Weight:").concat(" ").concat(p.getWeight());
l.info("Eye Color:").concat(" ").concat(p.getEyeColor());
l.gender("Gender:").concat(" ").concat(p.getGender());
aa++
}
}
do Whileループ
do {
statementsToExecute
} while (condition);
public static void main(String[] args) {
Logger l = Logger.getLogger(Person.class.getName());
int aa = 0;
do {
Person p = new Person("Joe Q Author", 42, 173, 82, "Brown", "MALE");
l.info("Loop execution iteration# " + aa);
l.info("Name: ").concat(" ").concat(p.getName());
l.info("Age:").concat(" ").concat(p.getAge());
l.info("Height:").concat(" ").concat(p.getHeight());
l.info("Weight:").concat(" ").concat(p.getWeight());
l.info("Eye Color:").concat(" ").concat(p.getEyeColor());
l.gender("Gender:").concat(" ").concat(p.getGender());
aa++
} while (aa < 3);
}
}
ループの終了
if (condition)
break;
public static void main(String[] args) {
Logger l = Logger.getLogger(Person.class.getName());
int aa = 0;
do {
if (aa == 1)
break;
Person p = new Person("Joe Q Author", 42, 173, 82, "Brown", "MALE");
l.info("Loop execution iteration# " + aa);
l.info("Name: ").concat(" ").concat(p.getName());
l.info("Age:").concat(" ").concat(p.getAge());
l.info("Height:").concat(" ").concat(p.getHeight());
l.info("Weight:").concat(" ").concat(p.getWeight());
l.info("Eye Color:").concat(" ").concat(p.getEyeColor());
l.gender("Gender:").concat(" ").concat(p.getGender());
aa++
} while (aa < 3);
}
}
ループの継続
if (condition)
continue;
public static void main(String[] args) {
Logger l = Logger.getLogger(Person.class.getName());
int aa = 0;
do {
if (aa == 1)
// break;
continue;
Person p = new Person("Joe Q Author", 42, 173, 82, "Brown", "MALE");
l.info("Loop execution iteration# " + aa);
l.info("Name: ").concat(" ").concat(p.getName());
l.info("Age:").concat(" ").concat(p.getAge());
l.info("Height:").concat(" ").concat(p.getHeight());
l.info("Weight:").concat(" ").concat(p.getWeight());
l.info("Eye Color:").concat(" ").concat(p.getEyeColor());
l.gender("Gender:").concat(" ").concat(p.getGender());
aa++
} while (aa < 3);
}
}