0% found this document useful (0 votes)
16 views

FOR Loop JAVA

The document explains the use of FOR loops in programming, highlighting their compact format for iterating through collections like arrays. It provides examples of initializing, using conditions, and iterating through arrays, as well as finding the length of an array. Additionally, it includes a simulation for authenticating a user based on paired username and password arrays.

Uploaded by

Joem Oliquino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

FOR Loop JAVA

The document explains the use of FOR loops in programming, highlighting their compact format for iterating through collections like arrays. It provides examples of initializing, using conditions, and iterating through arrays, as well as finding the length of an array. Additionally, it includes a simulation for authenticating a user based on paired username and password arrays.

Uploaded by

Joem Oliquino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

FOR Loop

• It is used when you want a Code Block to run repeatedly WHILE the
condition is Met.
• It is more compact format but more complicated version of a While
Loops are commonly used to iterate through Collection like Arrays
FOR Loop
For (initialization; condition; operation){

//do anything here

}
For Loop
for (int i=5; i<5; i++){

System.out.print(i);

}
Iterating Arrays
String[] names =(“joem”, “Emil”, “Haisen”, “Nelson”);

For (int i=0; i < 5; i++){

System.out.print(names[i]);
Array Lenght
• You can find the size of an array by calling their length variable (built
in variable in array)

String names= (“Joem”, “Emil”, “Haisen”, “Nelson”);

System.out.println(names.Length);
CONDITION in FOR Loop
• You can use Conditions inside for loop for different reasons like,
searching inside an array
String[] names =(“joem”, “Emil”, “Haisen”, “Nelson”);
for (int i=0; i < 5; i++){
if (names[i].equals(“joem”)){
System.out.print(“We found” + names[i]);
break;
}
Authenticating Simulation
• Create a program that has 2 sets of arrays w/ values already one for
the username and one for the password, the username and password
should be paired by index. Let the user input a username and
password then check if the account exists on the 2 sets of arrays.
• If the username and password doesn’t match then display “Account
not found”
• If the username and password matches then display
“Welcome(username)”

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy