OneCompiler

While loop

**write code for while loop.**

thes is code:

 #include <iostream>
 using namespace std;
 int main(){
   int a;
   
   while(a<11){
     a = a++;
     cout<<a;
   }
   cout<<"Finish";
 }
  • Result
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Finish
    _______________________________________

  • if a<11 print a, and print "Finish"

  • You can make your code last forever!

    • write:

while(1){
This means that the condition = is always true, meaning that as long as the condition is met, the process is repeated.

    • Creat your code!!!