[Java] Summary of for statements

Introduction

I am currently studying for the Java Silver exam. During my studies, I often mistakenly remembered or confused the for sentence, so I will summarize it from the basics in my own words.

Basic

for (initialization statement; conditional statement; update statement) { /// Iterative processing }

for(int i = 0; i < 10; i++) {
   System.out.println(i);
}

① Initialization sentence ② Conditional statement ③ Iterative processing ④ Update ⑤ Finish

Extended for statement

for (type variable name: set) { /// Iterative processing }

int[] array = {1, 2, 3}

for(int num : array) {
   System.out.println(num);
}

An image of taking out the contents of the set one by one from the beginning to the end.

Interruption of iterative processing

break Example: for (initialization statement; conditional statement; update statement) { if (conditional statement) {     break   } /// Iterative processing }

for(int i = 0; i < 10; i++) {
   if (i = 5) {
      break;
   }
   System.out.println(i);
}

When it breaks, it exits the iterative process (ends). In this case, System.out.println (i); after i = 5 is not executed.

continue Example: for (initialization statement; conditional statement; update statement) { if (conditional statement) {     continue   } /// Iterative processing }

for(int i = 0; i < 10; i++) {
   if (i = 5) {
      break;
   }
   System.out.println(i);
}

skips the one-time iteration process that was continued. In this case, only System.out.println (i); when i = 5 is not executed, and everything else is executed.

Summary

I have summarized the for statements that are often used in business. Personally, when I was a student, I was studying the basics of C language, and it was difficult to grasp the feeling of extended for sentences, so I would like to grasp it firmly.

Reference: Sumito Shiga "Thorough Strategy Java SE 8 Silver Problem Collection [1Z0-808] Compatible Thorough Strategy Series", Sokius Japan Co., Ltd., 2016

Recommended Posts

[Java] Summary of for statements
[For beginners] Summary of java constructor
[Java] Personal summary of conditional statements (basic)
Summary of Java support 2018
Summary of Java environment settings for myself [mac]
[Java11] Stream Summary -Advantages of Stream-
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
Summary of Java language basics
Summary of Java Math class
[Java] Summary of control syntax
Java while and for statements
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
Summary of file reading method for each Java file format
New grammar for Java 12 Switch statements
Summary of rails validation (for myself)
Summary of [Java silver study] package
Generics of Kotlin for Java developers
Summary of object-oriented programming using Java
Implementation of clone method for Java Record
[Java Silver] Summary of access modifier points
Java Generics Summary
Utilization of Java array elements, for, length, value, and extended for statements
For JAVA learning (2018-03-16-01)
[java] Summary of how to handle char
Java related summary
Summary of changes other than JEP of Java10
2017 IDE for Java
Java 8 documentation summary
List of download destinations for oracle java
[Java] [Maven3] Summary of how to use Maven3
Features of spring framework for java developers
Java Summary of frequently searched type conversions
Java 11 document summary
[Java] Overview of Java
Summary of Java Math.random and import (Calendar)
Java for statement
Practice of Java programming basics-I want to display triangles with for statements ①
Practice of Java programming basics-I want to display triangles with for statements ②
[java] Summary of how to handle character strings
A brief summary of Bootstrap features for beginners
[Java] Personal summary of classes and methods (basic)
[Java] Summary of how to abbreviate lambda expressions
Pre-introduction notes for JavaScript experienced learners of Java
A collection of simple questions for Java beginners
[Introduction to Java] Basics of java arithmetic (for beginners)
[Java] for statement, while statement
Expired collection of java
Predicted Features of Java
Java 12 new feature summary
[Java] Significance of serialVersionUID
[Summary] Java environment preparation
effective java 3rd summary
[Java] Package for management
NIO.2 review of java
Review of java Shilber
Java 13 new feature summary
[Java] for statement / extended for statement
Summary of OpenJDK sources