Iterative
Statement dks
vU; Programming Language dh rjg gh Java esa Hkh mi;ksx esa fy;k tkrk gSa ;g rhu izdkj ds gksrs gSa
(1) for
(2) While
(1) For: - blds varxZr tc dqN Statements dks
ckj&2 Repeat djuk gksrk gSa rks For Loop dks dke esa fy;k tkrk gSaA
Syntax:
- for (initialization;
Condition; iteration)
{
body;
// for loop
statements
}
(2) While Loop : -
Conditional Statements dks
rFkk Conditional Expressions dks Control djus ds fy, While
Loop dks
mi;ksx esa fy;k tkrk gSaA ;fn izksxzke ds varxZr While Loop esa
fy[kh xbZ Condition, False gksrh gSa rks While Loop esa fy[ks x;s Statements
dks Execute ugha fd;k tkrk gSaA
Syntax:
- while (Condition)
{
// body
}
Example:
- (while)
class Rev
{
public
static void main (String a [])
{
int n=10;
while
(n>0)
{
System.out.println(n);
n--;
}
}
}
Example:
- (for)
class Rev
{
public
static void main (String a[])
{
int
n ;
for
(n=10; n>0; n--)
{
System.out.println
(n);
}
}
}
(3) Do While Statements: - dHkh&2 ;g vko’;d gks tkrk gSa fd While Loop esa fy[ks x;s Statements
,d ckj rks Execute gks gh blfy, Do
while Loop dks
mi;ksx esa fy;k tkrk gSaA nwljs 'kCnksa esa tc User Termination Condition dks Test djuk pkgrk gSa] rks Do While Loop dk iz;ksx fd;k tkrk gSaA
Syntax:
- do
{
// Body of Loop
}
while (condition);
Example:
- class Rev
{
public
static void main (String a[])
{
int n=10;
do
{
System.out.println(n);
n--;
}
}
}
Example:-
*****
****
***
**
*
class My
{
public
static void main (String str[])
{
int
i,j;
for
(i=0; i<10; i++)
{
for
(j = i, j<10; j++)
System.out.print(*);
System.out.println();
}
}
}
No comments:
Post a Comment