Day15: Loop

Loop(Iterative Statement) In Java loops are two types: Entry Controlled Loop(Condition is tested before the body Ex:- while, for) Exit Controlled Loop(Condition is tested after loop body Ex:- do while) Syntax for while loop: while(test-condition) { //loop body } class PrintNos { public static void main(String[] args) { int i = x; while(i<=10); { System.out.println(i); i++; } } } Output : 1 2 3 4 5 6 7 8 9 10 Factorial by while loop import java.util.Scanner; class Factorial { public static void main(String [] args) { Scanner sc = new Scanner(System.in); int n,f = 1; System.out.println("Enter an int: "); n = sc.nextInt(); while(n>1) { f = f * n; n--; } System.out.println("factorial ...