Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java Loops in hindi (Java लूप्स क्या है ?) / Java loops कितने प्रकार के होते हैं ?


 


प्रोग्रामिंग भाषा में किसी वैल्यू की कुछ शर्तो पर जब पुनरावर्ती की जाती है तब loops का इस्तेमाल करते हैं।

Java - While Loop : Java While Loop in hindi 

While Loop जब तक condition true होती है तब तक loop repeat होता रहता है | अगर condition false होता है, तब Loop exit हो जाता है |


Syntax for While Loop :

1
2
3
4
5
6
variable_initialization;

while( condition ){
//statement(s);
increment/decrement;
}


Example for While Loop :

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
//WhileLoop.java
public class WhileLoop{

public static void main(String args[]) {

int i = 0;

while(i 10){

System.out.println("Value of i is " + i);
i++;
}
}
}


Output :

 1
2
3
4
5
6
7
8
9
10
Value of i is 0
Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4
Value of i is 5
Value of i is 6
Value of i is 7
Value of i is 8
Value of i is 9

Java - Do While Loop : Java Do while loop in hindi 

Do_while ये Loop; while Loop के जैसा ही है, लेकिन ये loop अगर condition true होती है तब do_while loop चलता है और condition false होती है तब सिर्फ do का statement execute हो जाता है |



Syntax for Do While Loop :

1
2
3
4
5
6
7
variable_initialization;

do{
//statement(s);
increment/decrement;
}
while( condition );


Example for do while loop :

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
//DoWhileLoop.java
public class DoWhileLoop{

public static void main(String args[]){

int i = 0;

do{
System.out.println("Value of i is " + i);
i++;
}
while(i 10);
}
}

Output :

 1
2
3
4
5
6
7
8
9
10
Value of i is 0
Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4
Value of i is 5
Value of i is 6
Value of i is 7
Value of i is 8
Value of i is 9


Java For Loop : Java for loop in hindi 

Core Java में for Loop के लिए दो प्रकार है |

  1. Normal for Loop
  2. Enhanced or foreach Loop

3.1 Normal for Loop : Java normal loop in hindi 

for loop में दिए हुए condition तक statement repeat होता रहता है |




Syntax for For Loop :

1
2
3
4
5
for( initialization; condition; increment/decrement ){

//statements;

}


Example for For loop :

 1
2
3
4
5
6
7
8
9
10
public class ForLoop{

public static void main(String args[]){

for( int i=0; i 10; i++ ){

System.out.println("Value of i is " + i);
}
}
}

Output :

 1
2
3
4
5
6
7
8
9
10
Value of i is 0
Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4
Value of i is 5
Value of i is 6
Value of i is 7
Value of i is 8
Value of i is 9

Enhanced or Foreach Loop : Java enhanced loop in hindi 

array के elements की value को print करने के लिए foreach का इस्तेमाल किया जाता है, लेकिन ये array के मामले में for loop से बेहतर रहता है |

Syntax for 'foreach' Loop :
1
2
3
4
5
for(variable_name : array_name){

//statement(s);

}

Example for Foreach Loop :

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//ForandForeachLoop.java
public class ForandForeachLoop{

public static void main(String args[]){

int[] arr = {10, 15, 20, 25, 30};

System.out.println("Using for Loop");
for( int i=0; iarr.length; i++ ){
System.out.println("Value of arr is " + arr[i]);
}

System.out.println("\nUsing foreach Loop");
for(int a : arr){
System.out.println("Value of arr is " + a);
}

}
}

Output :

 1
2
3
4
5
6
7
8
9
10
11
12
13
Using for Loop
Value of arr is 10
Value of arr is 15
Value of arr is 20
Value of arr is 25
Value of arr is 30

Using foreach Loop
Value of arr is 10
Value of arr is 15
Value of arr is 20
Value of arr is 25
Value of arr is 30



अगर आपको यह पोस्ट 📑 पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !


This post first appeared on Code In Hindi, please read the originial post: here

Share the post

Java Loops in hindi (Java लूप्स क्या है ?) / Java loops कितने प्रकार के होते हैं ?

×

Subscribe to Code In Hindi

Get updates delivered right to your inbox!

Thank you for your subscription

×