Skip to main content

Looping Statement in Java.

 

Firstly what is looping statement?

So, looping statement are those statement which are executed more than one time repeatedly until the user want.

There are Three looping Statement in Java.

1) for loop.

2) while loop.

3) do while loop.

Lets understand them by their syntax.

1) for loop





for loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly until the user wants.

Lets understand by one example:-


 






Here in the example we have initiated a class with name for_loop then we have main method in the main method we have for loop in that for loop we have statement in which i is initialize to 0 and i is less than 5 and i++ for incrementing the value of i. And in that for loop we have given a statement to print the value of i. Then we have completed the blocks and generated the output.

2) while loop







while loop is also a control flow statement that allows code to be executed repeatedly based on the given Boolean condition.

Lets understand by one example.








Here in the example we have initiated a class with name while_loop then we have main method in the main method we have initiated i=0 and after that we have while loop in that while loop we have statement in which i is less than 5 .And in that while loop we have given a statement to print the value of i and then incremented the value of i. Then we have completed the blocks and generated the output.

3) do while loop







do while loop is also 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.

Lets understand by one example







Here in the example we have initiated a class with name do_while_loop then we have main method in the main method we have initiated i=0 and after that we have do while loop in that do while loop we have given a statement to print the value of i and then incremented the value of i. Then we have  while block in which we have given that i is less than 5 then we completed the blocks and generated the output

Comments

Post a Comment

Popular posts from this blog

Best Programming Language to learn in 2021

The main aptitude to learn in this day and age is to realize how to compose a PC program. Today, PCs have entered in pretty much every industry. Be it the autopilot in an airplane or advanced speedometer in your bicycle, PCs in different structures encompass us. PCs are incredibly valuable for an association to scale up well. Gone are the times of pen and paper. Today, to store and access your data, you totally need PCs. The programming and engineer networks are arising at a rate quicker than at any other time. Different new programming dialects are coming up that are appropriate for various classifications of designers (tenderfoots, middle, and specialists) just as for various use cases (web application, versatile applications, game turn of events, disseminated framework, and so forth) Each amateur is astounded with the inquiry, "What programming language would it be advisable for me to learn?" Types of Programming  1. Procedural Programming Languages This programming worldv

Inheritance In Java

  Inheritance Inheritance is a process or a mechanism where one class acquire the properties which include methods and fields of another class. With the use of this concept the information is made manageable in a hierarchical order. The class which inherits the properties of another class is known as subclass  or derived class or child class . and the class whose properties are inherited is called as base class or parent class . In java inheritance cannot be achieved until we use extends keyword. Reason to use Inheritance 1 For Method overriding 2 For code reusability  Syntax: class abc { ......... ......... } class xyz extends abc { ......... ......... } ---------------------------------------------------------------------------------------------------------------------------- Example //WAP to Demonstrate Inheritance............. import java.io.*; class Superclass { BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); Double num1,num2; void get() { try

What is Procedural Programming Language(PPL)

  Procedural Programming Language. Procedural Programming might be the primary programming worldview that another engineer will learn. Essentially, the procedural code is the one that straightforwardly trains a gadget on the best way to complete an errand in consistent advances. This worldview utilizes a direct top-down methodology and treats information and techniques as two distinct elements. In view of the idea of a methodology call, Procedural Programming isolates the program into strategies, which are otherwise called schedules or capacities, just containing a progression of steps to be done.  Basically, Procedural Programming includes recording a rundown of directions to mention to the PC what it ought to do bit by bit to complete the job needing to be done.  Key Highlights of Procedural Programming  The vital highlights of procedural writing computer programs are given underneath:  1)Predefined capacities: A predefined work is normally a guidance distinguished by a name. For the