MeraForum Community.No 1 Pakistani Forum Community

MeraForum Community.No 1 Pakistani Forum Community (http://www.MeraForum.Com/index.php)
-   Java (http://www.MeraForum.Com/forumdisplay.php?f=217)
-   -   Loops In Java With Examples (http://www.MeraForum.Com/showthread.php?t=113303)

Morash 04-12-2014 01:07 AM

Loops In Java With Examples
 



Loops

A Statement Or A Set Of Statements That Is Executed Repeatedly Is Called Loop. The Statement In A Loop Are Executed For A Specified Number Of Times Or Until Some Given Condition Remains True.



Kinds

for Loop
while Loop
do-while Loop




for Loop

for Loop Is Used To Execute A Set Of Statements Repeatedly For A Fixed Number Of Times. It Has Some Parts, They Are;

Initialization
Condition
Increment Of Decrement
Body Of The Loop




Syntax

for ( initialization; condition; increment/decrement)
{
Statement;
}



Example

http://i57.tinypic.com/o86txt.jpg





while Loop

It Is A Conditional Loop Statement Used To Execute A Statement Or A Set Of Statements As Long As The Given Condition Remains True. After Executing The Statements Under 'while' The Control Shifts Back To 'while'
And The Condition Is Tested Again. If The Given Condition Becomes False At Any Stage During Execution, The Execution Of The Body Of Loop Is Terminated And Control Shifts To The Statement That Comes Immediately After The Body Of The Loop.


Syntax

while (condition)
{
Statement;
}


Example

http://i60.tinypic.com/e71oqf.jpg





do-while Loop

It Is Also A Conditional Loop Statement. It Is Like while Loop But In This The Condition Is Tested After Executing The Statement Of The Loop. In do-while Loop The Body Of The Loop Is Executed At Least Once Before The Condition Is Tested.
It Is Repeatedly Executed As Long As The Test Condition Remains True.


Syntax

do
{
Statement;
}
while(condition);



Example

http://i61.tinypic.com/25i262b.jpg




Flower~ 04-12-2014 10:41 AM

Re: Loops In Java With Examples
 
:bshy:
v nice

PRINCE SHAAN 04-12-2014 10:52 AM

Re: Loops In Java With Examples
 
Very nice sharing dear......................

Akash 04-12-2014 10:52 AM

Re: Loops In Java With Examples
 
http://i61.tinypic.com/34e2hab.png

AYAZ 04-12-2014 09:29 PM

Re: Loops In Java With Examples
 
Thanks morash for sharing such easily tutorial with examples.

Morash 04-13-2014 11:53 AM

Re: Loops In Java With Examples
 
Thanks All .


All times are GMT +5. The time now is 12:59 PM.

Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.