Page 66 - Modular_V2.0_C++_Flikpbook
P. 66

#include<iostream.h>
                  #include<conio.h>

                  void main()
                  {
                      clrscr();
                      int r;
                                                                                           DOSBox 0.74, Cpu speed: max 100%

                                                                                       Enter number of rows: 5
                      cout<< "Enter number of rows: ";
                                                                                       1
                      cin>> r;                                                         1 2
                                                                                       1 2 3
                      for(int i = 1; i <= r; i++)                                      1 2 3 4
                                                                                       1 2 3 4 5
                      {
                          for(int j = 1; j <= i; j++)
                          {
                              cout<< j << " ";

                          }
                          cout<< "\n";
                      }
                      getch();
                  }

                     INFINITE LOOP

                  A loop that never ends is called an infinite loop. If the condition in a loop never becomes false,
                  the loop will continue running indefinitely. To prevent an infinite loop, ensure that the condition
                  changes  somewhere  in the  loop’s header  or  body  so that  it can  eventually  become false.

                  For example:
                       int i = 10;

                       while(i <= 10)
                       {
                           cout<< "Hello";
                           i--;
                       }
                  The preceding loop will run infinitely, because the value of the variable i will never become
                  greater than 10.

                                 Tech Funda




                         An infinite loop can be stopped by pressing Ctrl + Break key.





                   64
                          Touchpad MODULAR (Ver. 2.0)
   61   62   63   64   65   66   67   68   69   70   71