-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestLoops.java
48 lines (38 loc) · 973 Bytes
/
TestLoops.java
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
/*
This class introduces a while loop
*/
public class TestLoops{
public static void main(String[] args){
/*
while(conditional statement){
//do stuff
}
*/
//we can print out numbers like this
System.out.println(1);
System.out.println(2);
System.out.println(3);
System.out.println(4);
System.out.println(5);
System.out.println(6);
System.out.println(7);
System.out.println(8);
System.out.println(9);
System.out.println(10);
//or we can use a loop to print out the numbers
int start = 1;
int end = 100;
boolean flag = true;
//this is a while loop
while(!flag || start <= end){
System.out.println(start); //this prints out the number
start = start + 1; //this is the same as start++;
//condition that makes the flag false
//so that it only prints up to 50
if(start == 50){
flag = false;
}
}//end of while loop
System.out.println("Done!");
}//end of main
}//end of class