Get the App
SLTechnology News&Howtos  ›  Development  › 

Introduction to the basics of Java: how to use For loops

Shulou Source: shulou.com Published: 2022-06-03 01:00:47 10月03日 Update

This article mainly explains the "introduction to Java basic how to use For cycle", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "introduction to Java how to use For cycle" bar!

I. for Loop statement

1. In java, it is generally used when the number of times is determined. If you want repetitive instruction execution, you can use a for loop. The basic syntax is as follows:

For (initialization expression; Loop condition; Action expression) {C1: execute statement. }

After the for keyword in the above syntax statement, there are three contents, initialization expressions, loop conditions, and action expressions, separated by semicolons (;), and there is an execution statement in the curly braces as the loop body. How is this for loop statement executed?

Take four steps:

Step 1: initialize the expression first

Step 2: execute the loop condition to determine whether the condition is satisfied. If the condition is satisfied, execute the statement of C1. If the condition is not satisfied, exit the for loop.

Step 3: execute the statement of C1

Step 4: execute the action expression, and then repeat the second step

two。 Use the for loop to find the value of the sum of integers from 1 to 10

The code is as follows:

Int sum = 0; for (int I = 1; I

Tags: Loops conditions statements expressions output code variables outer layers arrays inner layers integers types results bases elements multiplication multiplication tables content syntax jangles + Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info vpn Huawei macOS