Pages

Pages - Menu

Friday, 1 March 2013

Introduction of While loop

While लूप बहुत ही महत्वपूर्ण लूप है . इस लूप को हम जब तब चलाते है जब तक की इस लूप के अंदर 
की condition false नहीं हो जाती । जैसे की हमे दो दी टेबल लिखनी है तो हम प्रोग्राम को बता सकते है
की हम टेबल तब तक प्रिंट करना चाहते है जब तक i की value १० नहीं हो जाये| 
इस प्रोग्राम में हम २ की टेबल प्रिंट करेंगे . यह बहुत आसन प्रोग्राम है आप इसको एक बार बनाये और
फिर इसको समझने की कोशिश करे तो आपको While लूप का महत्व भी पता लग जाएगा । 











/ ************************************************* ************************ 
* Compilation: javac TwoTableljava 
* Execution: Java TwoTable 
* 
ME * until the value 10 of the two tables do not print be. For these values ​​i = 1 to 10. 
* While this work we will consider with the loop and repeat again and again While the work  
can be done from * loop. 
*% Java TwoTable 
* 2 * 1 = 2 
*   2 * 2 = 4 
*   2 * 3 = 6
* 2 * 4 = 8 
*   2 * 5 = 10 
*   2 * 6 = 12
 * 2 * 7 = 14
*   2 * 8 = 16 
*   2 * 9 = 18 
 * 2 * 10 = 20
 
* 
************************************************* ************************ /

public class TwoTable { 
   public static void main (String [] args) {

      / / Old way without the while loop  
      System.out.println ("2 * 1 = 2");
      System.out.println ("2 * 2 = 4");
      System.out.println ("2 * 3 = 6");

      / / The rest of the table while loop with new ways in which we do it 
      int i = 4;
      while (i <= 10) {
         System.out.print ("2 *" + i + "="); 
   System.out.println (2 * i);
         i = i + 1;
      }

   }
}

No comments:

Post a Comment