How To Use For Loop In Selenium
Coffee Loop:
- In some situation y'all need to execute a cake of code several number of times in such a example loops are used.
- A java loopargumentpermits u.s. to execute astatement orgroup of statementsmultipletimes and following isthe generalcourseof a loopargument innearly of the programming languages.
- Looping in programming languages is acharacteristic whichhelpsthe execution ofa ready ofinstructions/functionsagain and againwhilea fewsituation evaluates totruthful.
- Javaprovidesthreemethods for executing the loops.
- whileall theapproachesoffersimilarsimplecapability, theyrangeof their syntax andcondition checking time.
Coffee supports following loops:
- while Loop
- do…while Loop
- for Loop
- for each loop
- Java Go on Statement
- Coffee Break Statement
ane) The while Loop:
- A while loop is acontrolshape thatallows y'allto echo aassignment forsurenumber oftimes.
- while executing, if thecondition isactual, then thedeportmentinside the loopmight bedone.
- This couldretainas long as thestatus istrue.
- While loopbegins with the checking ofsituation. If it evaluated tobodily, then the coffee loopbody statements areexecutedin any other case offsetstatement following the loop isachieved.
- For that reasonit is alsoreferred to asaccesscontrol loop
Syntax:
while ( condition ) { //Statements } |
Case:
bundle package_Java ; public grade While_Java { public static void principal ( Cord args [ ] ) { int 10 = ten ; while ( x & lt ; xv ) { System . out . print ( "value of ten : " + x ) ; x ++ ; System . out . print ( "\n" ) ; } } } |
Output:
value of 10 : x value of ten : xi value of 10 : 12 value of x : xiii value of x : 14 |
2) The do…while Loop:
- A do…while loop ismuch similara while loop,besidesthat a do…while loop isassured to executeas a minimum ane time.
- Thesituationappearson theterminate of the loop, then the statementswithin the coffee loop executeas soon every bitbefore thecondition isexamined.
- If thecondition isproper, themenstruation ofcontrol jumpsreturnedas much as practise, and the statementsin the loop executeonce again.
- This canagreeand then long as thecondition isactual.
Syntax:
practise { //Statements } while ( status ) ; |
Example:
package package_Java ; public course Do_While_Java { public static void main ( String args [ ] ) { int x = 10 ; do { System . out . print ( "value of x : " + x ) ; x ++ ; System . out . print ( "\due north" ) ; } while ( x & lt ; 13 ) ; } } |
Output:
value of x : x value of x : 11 value of x : 12 |
3) The for Loop:
-
for loop is a repetitioncontrolstructure that executea detailnumber oftimes.
-
for loop isusefulwhen yousrecognize howin many instances atask is to be repeated.
Syntax:
for ( initialization ; condition ; increase / decrement ) { // } |
Instance:
package package_Java ; public course For_Java { public static void chief ( String args [ ] ) { for ( int x = 10 ; x & lt ; 13 ; 10 = x + 1 ) { Organization . out . impress ( "value of x : " + x ) ; Arrangement . out . print ( "\northward" ) ; } } } |
Output:
value of x : ten value of x : 11 value of x : 12 |
4) The for each Loop:
- it isspecially used to traverse array orcollectionfactors.
- Thegain of for-every coffee loop is that information technologyeliminates theopportunity ofbugs and makes the lawmakingextra readable.
Syntax:
for ( data_type variable : ( array or collection ) ) { //... } |
Example:
package package_Java ; course For_Each_Java { public static void main ( String args [ ] ) { int arr [ ] = { 12 , 13 , 14 , 44 } ; for ( int i : arr ) { Organisation . out . println ( i ) ; } } } |
< bridge style = "text-decoration: underline;" > < strong > Output : < / strong > < / span > |
5) Java Continue Statement:
- The Javakeepargument is used tocontinue loop until statement is true.
- Itcontinues thecurrentfloat ofthis system and skips theremaining code atspecialcondition.
- In case ofinternal loop, information technologycontinuesonlyinternal loop.
Syntax:
Example:
parcel package_Java ; public class Continue_Java { public static void master ( String [ ] args ) { for ( int i = i ; i & lt ; = 10 ; i ++ ) { if ( i == v ) { proceed ; } System . out . println ( i ) ; } } } |
Output:
6) Java Break Statement:
- The Coffeebreak is usedto suspension loop orswitchstatement until statement is true or faux.
- It breaks thecurrentgo with the flow ofthis system atexactcondition.
- In case ofinternal loop, it breaksonlyinternal loop.
Syntax:
Case:
packet package_Java ; public form Break_Java { public static void main ( String [ ] args ) { for ( int i = one ; i & lt ; = 10 ; i ++ ) { if ( i == five ) { break ; } Arrangement . out . println ( i ) ; } } } |
Output:
How To Use For Loop In Selenium,
Source: https://stqatools.com/java-loop-control/
Posted by: alexanderdellittef1972.blogspot.com
0 Response to "How To Use For Loop In Selenium"
Post a Comment