Page 169 - CA_Blue( J )_Class10
P. 169
Statements inside loop;
if(condition)
{
break;
}
Statements inside loop;
}
st
1 statement after loop;
Program 8 To input a number and print whether the number is a prime number or not.
1 import java.util.*;
2 public class main {
3 public static void main(String[] args) {
4 int n = 0;
5 Scanner sc = new Scanner(System.in);
6 System.out.println("Enter the num: ");
7 n = sc.nextInt();
8 boolean f = false;
9 for (int i = 2; i <= n / 2; ++i) {
10 if (n % i == 0) {
11 f = true;
12 break;} }
13 if (!f)
14 System.out.println(n + " is a prime number.");
15 else
16 System.out.println(n + " is not a prime number.");
17 }
18 }
You will get the following output:
8.8.2 The continue Statement
The continue statement is used to control the loop by sending the control to the next iteration. When it is executed
the current flow stops and skipping the remaining code goes to the next iteration. All three types of loops can use the
continue statement.
167
Iterative constructs in Java 167

