1Create a loop that runs as long as i is less than 10, but increase i with 2 each time.
2
3var i = 0
4
5while(i < 10){
6 console.log(i);
7 i = i + 2;
8}
1Create a loop that runs as long as i is less than 10.
2
3var i = 0;
4
5while(i < 10) {
6 console.log(i); i++
7}
1A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.
2
3Syntax :
4while(Boolean_expression) {
5 // Statements
6}
7Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non zero value.
8
9When executing, if the boolean_expression result is true, then the actions inside the loop will be executed. This will continue as long as the expression result is true.
10
11When the condition becomes false, program control passes to the line immediately following the loop.
1A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.
2
3Syntax :
4while(Boolean_expression) {
5 // Statements
6}
1#include<stdio.h>
2
3int main()
4{
5 printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
6
7 /*
8 always declare the variables before using them
9 */
10 int i = 0; // declaration and initialization at the same time
11
12 printf("\nPrinting numbers using while loop from 0 to 9\n\n");
13
14 /*
15 while i is less than 10
16 */
17 while(i<10)
18 {
19 printf("%d\n",i);
20
21 /*
22 Update i so the condition can be met eventually
23 to terminate the loop
24 */
25 i++; // same as i=i+1;
26 }
27 printf("\n\n\t\t\tCoding is Fun !\n\n\n");
28 return 0;
29}
1While(condition is true) {
2
3// Code // The block keeps executing as long as the condition is true
4
5// Code
6
7}