while loop to for loop code example

Example 1: while loop

var i=1;
while(i<=10){
document.write(i + "<br>");
i++;}

Example 2: while loop

i = 0

while i < 6:

    i += 1

  if i == 3:
    continue
  print(i)

Example 3: while loop

#include<stdio.h>

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");

    /* 
        always declare the variables before using them 
    */
    int i = 0;  // declaration and initialization at the same time

    printf("\nPrinting numbers using while loop from 0 to 9\n\n");

    /* 
        while i is less than 10 
    */
    while(i<10)
    {
        printf("%d\n",i);

        /* 
            Update i so the condition can be met eventually 
            to terminate the loop 
        */
        i++;    // same as i=i+1;
      }
    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}

Tags:

Cpp Example