alternative
  • Home (current)
  • About
  • Tutorial
    Technologies
    Deep Learning
    Statistics for AIML
    Natural Language Processing
    Machine Learning
    SQL -Structured Query Language
    Python
    Ethical Hacking
    Java
    Placement Preparation
    Quantitative Aptitude
    View All Tutorial
  • Quiz
    SQL -Structured Query Language
    Quantitative Aptitude
    Java
    View All Quiz Course
  • Q & A
    Quantitative Aptitude
    Java
    View All Q & A course
  • Programs
  • Articles
    Artificial Intelligence & Machine Learning Project
    How to publish your local website on github pages with a custom domain name?
    How to download and install Xampp on Window Operating System ?
    How To Download And Install MySql Workbench
    How to install Pycharm ?
    How to install Python ?
    How to download and install Visual Studio IDE taking an example of C# (C Sharp)
    View All Post
  • Tools
    Program Compiler
    Sql Compiler
    Replace Multiple Text
    Meta Data From Multiple Url
  • Contact
  • User
    Login
    Register

Java - Decision Control and looping statement - For Tutorial

For loop

The Java for loop is used When you exactly know how many times the loop should be executed.

For example- Suppose you want to execute “hello” three-time

public class forloop 
{
public static void main(String[] args) 
{
for (int i = 0; i < 3; i++) 
{//Starting from i=0,0<3 true,then i=1,1<3 true, then i=2,2<3
System.out.println("Hello");
}
}
}

Run Program

 

Program explanation-

It Checks for a condition if it is true or not.

My value is set to 0, 0 is less than 3, hence it will print 1st Hello.

I value get incremented by 1,making it i=0+1=1

I=1 is less than 3, true, hence it will print 2nd Hello.

I value get incremented again by 1, making it i=1+1=2

I=2 is less than 3, true, hence it will print 3rd Hello.

I value get incremented again by 1, making it i=2+1=3

I=3 is not less than 3, false, hence the loop will stop.

 

For-each Loop

This loop will not check the condition, it will print each statement in the array.

 

public class ForEachLoop 
{
public static void main(String[] args) 
{
int[] value = {1,2,3,4};
for (int i : value) 
{
System.out.println(i);
}
}
}

Run Program

 

Java

Java

  • Introduction
  • Installation and running a first java program
    • JDK Installation
    • Environment Variable Path Setup
    • Running a first java program
  • 1st Java Program Explanation
    • Program Syntax
  • JDK,JRE,JVM
    • JRE
    • JDK
    • JVM
  • Thing to know before proceed
    • Variable
    • Datatype
    • Operator
    • Keyword
    • Access Modifier
  • Decision Control and looping statement
    • If-else
    • Switch
    • For
    • While
    • do-while
    • break
    • continue
  • Object-Oriented Programming (OOPS) Concept
    • About OOPs
    • Object & Class
    • Inheritance
    • Polymorphism (Runtime & Compile Time)
    • Abstraction (Using abstract and interface)
    • Encapsulation

About Fresherbell

Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique

Important Links

Don't hesitate to give us a call or send us a contact form message

Terms & Conditions
Privacy Policy
Contact Us

Social Media

© Untitled. All rights reserved. Demo Images: Unsplash. Design: HTML5 UP.