Loops ; Java
Loops are structures that are run repeatedly according to the instructions or conditions.
There are two types of loops in Java: a while loop and a for loop, both are written differently.
Conditions
A for-loop uses the syntax of for(int *var_name* = *value* ; *var_name with condition*; *change value of var_name*)
A while loop uses the syntax of while(*condition*) but the variable(s) must be created before the loop.
Syntax ; Writing
Here is the list:
- int __ = ___;
- String __ = ___;
- boolean __ = ___;
- ArrayList <__> __ = new ArrayList <__> ;
- A class must have the first letter at an uppercase
- Name of the java file must match with the class name
- If a variable is written with more than one word - write it as uppercase of the first letter of the second word
(ex:myName) - Writing a for loop with a condition that exceeds the limit of a value or length will result an OutOfBounds exception
- Write the variable type correctly - variables like int or boolean are not uppercase(unless you are creating an ArrayList).
public class Main{
}
Comments & Inputs ; Writing
When writing comments, you use a double slash (//)
For inputs you need to import the scanner module as shown.