💡 Arrays are not data types; they are data structures.
Example: Declaring an array capable of holding 8 characters of type 'char’
public class Main {
public static void main(String[] args) {
char[] str = { 's', 'o', 'f', 't', 'w', 'a', 'r', 'e' };
System.out.println(str); // software
}
}
int i = 0; // Helper variable declaration
while(i < 10) { // Condition in parentheses
i++; // Update helper variable
}
Example: Infinite while loop
while(true){
// Infinite loop
}
for
: Signals the start of the loop.(start; condition; update)
is written in sequence.int index = 0;
: Variable used for the condition.index < integers.length;
: Logical expression. If true, execute the code inside the curly braces. If false, exit the loop.index++
: Increment the index by 1.{}
Curly braces: Contains the logic to execute when the logical expression of the loop is true.Example: Loop to iterate over each character in an array