Mega Code Archive

 
Categories / C++ Tutorial / Operators Statements
 

Use three conditions in while statement

#include <iostream>    int main()  {      unsigned short small = 1;      unsigned long  large = 123;      const unsigned short MAXSMALL=65535;        std::cout << "small: " << small << "...";         // for each iteration, test three conditions      while (small < large && large > 0 && small < MAXSMALL)      {          std::cout << ".";          small++;          large-=2;      }      std::cout << "\nSmall: " << small << " Large: "  << large << std::endl;      return 0;  } small: 1............................................ Small: 42 Large: 41