-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileLoop.java
More file actions
48 lines (43 loc) · 1.53 KB
/
Copy pathWhileLoop.java
File metadata and controls
48 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package Phase1_CoreLanguage.Loops;
/**A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
* The while loop can be thought of as a repeating if statement.
* While Loop first check the condition if the condition is true then it'll execute else exit form the loop.
* <p>
*
* Syntax :
* While(boolean condition){
* loop body
* }
* <p>
*
* FlowChart:
* <p>
*
* Start ----->Condition Check----->if true----->Loop Body Execute --------->Condition Check----->if false----->Exit
* <p>
*
* While loop starts with the checking of condition.
* If it evaluated to true, then the loop body statements are executed otherwise first statement following the loop is executed.
* For this reason it is also called Entry control loop
* Once the condition is evaluated to true, the statements in the loop body are executed.
* Normally the statements contain an update value for the variable being processed for the next iteration.
* When the condition becomes false, the loop terminates which marks the end of its life cycle.**/
public class WhileLoop {
public static void main(String args[])
{
int x = 1;
// Exit when x becomes greater than 4
while (x <= 4)
{
System.out.println("Value of x:" + x);
// Increment the value of x for
// next iteration
x++;
}
}
//OUTPUT
//Value of x:1
//Value of x:2
//Value of x:3
//Value of x:4
}