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

Decision Making Statements in Java Programming Language.

 Their are 3 decision making statement in Java. Here where ever you find the if underlined like this( if ) then it is related to statement. 1) if statement. 2) if else statement. 3) if-else-if statement. So lets discuss one by one about each statement. 1) if statement:- if statement is used in programming for checking the given condition is true or not. If the condition in the if block is true then the block executes otherwise the programme terminates. Lets understand it by its syntax.   Here in the syntax we have condition in the if block, if the the condition which we have putted is true then the code which is written in the block will executes otherwise the programme ends their.  2) if else statement:- if else statement is used in programming for checking the given condition is true or false. If the condition is true then the if block is executed otherwise the else block is executed. Lets understand it by its syntax. Here in the syntax a condition is given in the if...

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 distingu...

Packages In Java

  Package in java is a group of similar type of classes, interface and sub-package. Packages in java can be defined in two ways which are 1 Built-in Packages 2 User-defined Packages Built-in Packages are       * Lang      * Util      * io      * awt      * net      * applet, etc. User-defined packages can be anything which are created by the user. Packages are nothing but container of the classes which store the no of classes, interface and their methods. Advantages of Packages 1 It provide access Protection 2 It removes the naming collision 3 it is used to categorize the classes and interface so that they can be easily maintained. Steps for creating a package Step-1 Create a folder in any drive of your choice  Step-2 example in d: package1 (it is the name of the package) Step-3 Open the java application and type the following code package package1; public class demo {  publ...