Loop

loop

Do while loop:
                          In most computer programming languages, a do while loop is a control flow statement that executes a block of code at least once, and then either repeatedly executes the block, or stops executing it, depending on a given boolean condition at the end of the block.

For loop:    
                 In computer science, a for-loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly.

For loop:
                In computer science, a for-loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly.


The program you see bellow is the mixture of all loop;

package com.ritesh;

import java.util.Scanner;

public class loop {
public static void main(String[] args) { //main function
while_loop();
do_while_loop();
for_loop();

}
public static void while_loop() // while loop
{
System.out.println("Enter How many time you want to print I am Student;");
Scanner sc=new Scanner( System.in);
short name=sc.nextShort();
String name2="I am a Student;";
int a = 1;
while(a<=name)
{
System.out.println(a+". "+name2);
a++;
}

}


public static void do_while_loop() // do while loop
{
System.out.println("Enter how many time you want to print I am a boy");
Scanner sc=new Scanner(System.in);
int size=sc.nextInt();
int m=1;
do{
System.out.println("I am a boy");
m++;
}
while(m<=size);
}
public static void for_loop() //for loop
{
System.out.println("Enter how many time you want to print I am a good student");
Scanner sc=new Scanner(System.in);
byte tot= sc.nextByte();
String name="I am a good student";
for(int i=1;i<=tot;i=i+1)
{
System.out.println(name);
}
}
}


         


   
   

Comments