Skip to main content

#loop #typesofloop What is loop | How to use loop | Type of loop | comp...

What is loop | Types of loop | When should you choose loop | when you decide to good for loop | What is the need of loop.

If you want to know about the loop than learn to hear. I am going to introduce the loop.
Q1.What is loop
 Ans: Loop is a technique to execute a block of statements multiple times. we can if you want to execute the statement multiple times then keep this statement inside the loop. through the loop, we can reduce the length of the program and the complexity of the code. types of loop.


Types of the loop:

   Basically, the loop is two types of 1.exit control loop and the other one is 2.entery control loop
   1.Exit control loop-
       The loop which is control after execution than goes for the exit control loop.
       like- do-while loop
         class A{
          
         public static void main(String args[]){
             int i=1;
             do{
                        System.out.println("Hello");
           }while(i++<10);
         }
       
     }
   So, In this example, you know the syntax of the do-while loop.

2.Entry control loop:
   
      In the entry control loop, you have to check the condition first then come inside the loop. if the condition is true.
like:  while() loop and for() loop.

So, I am going to introduce both for() loop and while loop syntax.
for() loop: If you know the ending point of iteration or how many times you have to iterate than go for() loop.

    class A{

        public static void main(String args[]){
         
         for(int i=0;i<10;i++){
            System.out.println("Hello");
           }
       }

}

In this example, you already know how many times you have to iterate the loop then choose the for a loop.

While() loop: If you don't how many times you have to iterate the loop then go for a while() loop because all the conditions are we don't know about this.

  class A{

      public static void main(String args[]){
       
         int i=10;
         while(i!=0){
             System.out.println("Hello");
             i=i/2;
          }
    }
 }
 





    

Comments

Popular posts from this blog

#Logic How to convert String Characters lower to upper and upper to low...

How to convert String Characters.  lower to upper and upper to lower How to Convert all the String character Upper and lower . If String character is lower than convert Upper If it is Upper than you have to convert a lower. I am going to introduce it is a very simple and easy way. String Conversion is very easy through the toUpperCase() and toLowerCase(); Method But I am going to do this Question without using the Inbuilt method in the class. You have to do this Only For logical coding Question. So, Finally, I am going to do this Question step-by-step if you want to watch videos than you can watch. In these videos, I discuss this question in a very simple and easy way. You have to take one class with the main method.                class Test{                 public static void main(){                    //your logic ...

Top 97 logical coding Question | for Freshers for getting a job in MNC Company | by er prince kumar

            Top 97 logical coding Question  for Freshers  If you do this you will become good logical programmers Write a Java program to perform input/output of all basic data types. Write a Java program to enter two numbers and find their sum. Write a Java program to enter two numbers and perform all arithmetic operations. Write a Java program to enter the length and breadth of a rectangle and find its perimeter. Write a Java program to enter the length and breadth of a rectangle and find its area. Write a Java program to enter the radius of a circle and find its diameter, circumference, and area. Write a Java program to enter the length in centimeter and convert it into meter and kilometer. Write a Java program to enter the temperature in Celsius and convert it into Fahrenheit. Write a Java program to enter the temperature in Fahrenheit and convert to Celsius Write a Java program to convert days into years, weeks and days....

Java objective question for written Test | Java written test objective question

                               Java objective question All the best important question ------------------------------------------------------------------------ 1. Answer: Illegal combination of final and abstract class 2. Answer: 4 3. Answer:    error: bad operand types for binary operator '=='                 System.out.println("Helo"+10==10); 4. Answer:   error: integer number too large                 System.out.println(08); Q5. ====  class Nit { public static void main(String[] args) { m1(2); } public static void m1(int i) { if (i >= 0) { m1(i - 1); } System.out.println(" " + i); }} output:  -1  0  1  2 ================================== Q.2 ------ ...