Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Example of a FOR Loop

public class Test {

   public static void main(String args[]) {

      for(int x = 10; x < 20; x = x + 1) {
         System.out.print("value of x : " + x );
         System.out.print("
");
      }
   }
}
Comment

what are for loops

# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:

x = 0
y = 3
while x < y:
    print(x)
    x = x + 1

>>> 0
>>> 1
>>> 2

# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change

######################################################################

# below is the equivalent for loop:
for i in range(0, 3):
    print(i)

>>> 0
>>> 1
>>> 2

# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
Comment

PREVIOUS NEXT
Code Example
Java :: java byte data type 
Java :: CORS with Spring Boot 
Java :: how to remove leading space in java 
Java :: void * to int 
Java :: how to compare two strings in java 
Java :: POST method) in spring rest api 
Java :: java println format 
Java :: How to remove an element from a Java List? 
Java :: find subarray with given sum 
Java :: android studio tabbed activity 
Java :: jre in java 
Java :: classpath in java 
Java :: minecraft addlayer(u) in the type rendererlivingentity<t is not applicable for the arguments 
Java :: output folder director 
Java :: output of this 
Java :: Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (execution: default-compile, phase: compile) 
Java :: @embeddedid 
Java :: pvector maximum dimension 
Java :: restore 
Java :: syntax for new module creation in java 
Java :: unirest javafx 
Java :: primitive vs wrapper classes in java 
Java :: make new file in intellij for java 
Java :: SmallChange 
Java :: convert boolean to Boolean class 
Java :: computeifabsent hashmap java 
Java :: java lambda expression in priorityqueue 
Java :: Creating strings using the new keyword Java 
Java :: @parameters on test use jupyter junit api 
Java :: min,max functions in java 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =