Java iteration

Introduction

Honestly I can't understand how to write a class at all (irrelevant to this content)

Iterative processing

Iterative processing is a process that automatically repeats a certain process ** while ** statement and ** for ** statement

kane.java


while(conditions){
Repeated processing;
}

for(conditions){
Repeated processing;
}

kane.java


int = 1;                     //Initialization

while(i <= 5){ //conditions
 System.out.println(i);      //Repeated processing
 i++;                        //Variable update that adds 1
}

for(int i = 1; i <= 5; i++){ //Initialization, conditions, updates can be written together
 System.out.println(i);      //Repeated processing
}

If you forget to add ** 1 to the variable **, the variable remains ** 1 **, and the condition becomes ** forever true **, so the iteration process is performed infinitely (infinite loop).

break In order to end the repetition, there is a method of forcibly ending ** using ** break other than setting the ** condition to false **. By combining with conditional branching such as if statement, iterative processing can be ended at any place.

kane.java


for(int i = 1; i <= 10; i++){ 
 if (i > 5){ //Forced termination when it reaches 6
  break;
 }
 System.out.println(i);      
}

continue continue can skip only the processing of that lap and execute the next lap. It is common to use continue in combination with if statements.

kane.java


for(int i = 1; i <= 10; i++){ 
 if (i % 3 == 0){ //Skip when it is a multiple of 3 and perform the next process
  continue;
 }
 System.out.println(i);      
}

console


1
2
4
5
7
8
10 

** Multiples of 3 are skipped **

At the end

28 years old who notices the effect of coffee now.

Recommended Posts

Java iteration
Java
Java
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java string
java (array)
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Polymorphism
Studying Java # 0
Java review
Java features
[Java] Inheritance
FastScanner Java
Java features
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface
Java9 collection
Java basics
Java methods
Java diary
Java inheritance
[Java] enum