Intro
This examples, will demonstrates how to use For loop statement using Java program.
Examples
package com.freesamplecode.java.basic; public class ForLoopDemo { public static void main(String[] args){ //first form for(int i = 0; i < 10; i++){ System.out.println(i); } String[] fruits = {"Apple", "Banana", "Cherry", "Pinneaple", "Strawberry"}; //second form for(String fruit : fruits){ System.out.println(fruit); } } }
Output
0 1 2 3 4 5 6 7 8 9 Apple Banana Cherry Pinneaple Strawberry
0 comments: