-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow statements
53 lines (48 loc) · 1.07 KB
/
flow statements
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
49
50
51
52
53
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// for loop
for(int i=0;i<n;i++){
System.out.println(i);
}
// while loop
int i=0;
while(i<=n){
System.out.println(i);
i++;
}
// do-while loop
int i=0;
do{
System.out.println(i);
i++;
}while(i<=n)
// break statemnet (this is used to come out from loop when the condition is fullfilled) break statement is used with flow and conditional statements
for(int i=0;i<n;i++){
if(i<=5){
System.out.println(i)
break;
}
}
// continue statemnet (this is used skip only this iteration and continue with loop)
for(int i=0;i<n;i++){
if(i==5){
System.out.println(i)
continue;
}
}
// nested loop
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
System.out.print("*");
}
System.out.println();
}
}
}