javaScript Loop

To run a code line two or more times, you can write the same code again and again but this will increase the size of the code and also take more time, so if any code line or content in the programming language has two or more If you want to run the bar, use the loop, the code line runs until the condition given in the loop is false. Loop is of 3 types -

1 For Loop

2 While Loop

3 Do While Loop

1. For Loop

If the condition and statement are given in the For loop, the loop does not run if the condition is false, if the condition is true then the code statement / content continues until the condition given in the loop is false.

Example 1

<?php

for($n=11;$n<=15;$n++){

echo "$n<br/>";

}

?>

Output

11
12
13
14
15

2. While Loop

While loop works like a for loop, in this also the condition and statement are given, the loop does not run when the condition is false and if the condition is true then the code statement / content continues until the condition given in the loop is false. .

Example 2

<?php

$n=11;

while ( $n <= 15) {

echo "$n <br/>";

$n++;

}

?>

Output

11
12
13
14
15

3. Do While Loop

Do while loop es condition and statement is given, if the condition is true then the code statement / content continues until the condition given in the loop is false. If the condition is false then a loop is run and the output is displayed in the web page because the code in the do while loop checks the interpreter condition after the statement / content is run.

Example 3

<?php

$n=20;

do{

echo "$n<br/>";

$n++;

}while($n<=15);

?>

Output

20


Connect with us

facebook logo
Email : contact@amcodestar.com
© Copyright amcodestar.com 2020 - 2023 All Rights Reserved.
About us     term and condition      comment policy
DMCA.com Protection Status