Loops :
- Loops are used to execute a set of statements repeatedly until a particular condition is satisfied.
Types of Loops :
for loop: This executes a statement a particular number of times.
while loop: This executes a statement an unknown number of times.
do-while loop: This executes a statement at least one time.
The syntax for the "for" loop is :
for(Variable Initialization; Boolean_Expression Test; Increment/Decrement){
//Statements
}
Example :
package selenium;
public class Java_practise {
public static void main(String[] args) {
// This will print -- 0,1,2,3,4,5
for(int Increment = 0;Increment<=5;Increment++){
System.out.println("Count is ==> " + Increment );
}
// This will print -- 5,4,3,2,1,0
for(int Decrement = 5;Decrement>=0;Decrement--){
System.out.println("Count is ==> " + Decrement );
}
// This will print -- 0,2,4
for(int Increment = 0;Increment<=5;Increment+=2){
System.out.println("Skip every one another ==> " + Increment );
}
// This will print -- 0,1,2,3,4,5
for(int Count = 0;Count<=10;Count++)
{
if(Count==6){
break;
}
System.out.println("Count is ==> " + Count );
}
// This will just print -- 3
for(int Count = 0;Count<=5;Count++){
if(Count==3){
System.out.println("Count is ==> " + Count);
continue;
}
}
}
}
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
No comments:
Post a Comment