Used to execute different blocks of code based on conditions.
- if
- if-else
- else-if ladder
- switch
int age = 18;
if(age >= 18){
System.out.println("Eligible for voting");
}
else{
System.out.println("Not eligible");
}
Used to execute a block of code repeatedly.
- for loop
- while loop
- do-while loop
for(int i = 1; i <= 5; i++){
System.out.println(i);
}
Used to alter the normal flow of execution.
- break
- continue
- return
for(int i = 1; i <= 10; i++){
if(i == 5){
break;
}
System.out.println(i);
}