Home QBASIC C Java HTML
  • More Courses
  • MCQs
  • Blog Download
  • Tools
  • Contact

    Contents

    WHILE .... WEND


    In a WHILE ... WEND loop, if the condition is True, all statements are executed until WEND keyword is encountered. If the condition is false, the loop is exited and the control jumps to very next statement after WEND keyword.

    Syntex: 

     
    WHILE
         [statements]
    WEND
    

    Example 1

    WAP to print the natural numbers from 1 to 10

    CLS
    n = 1
    WHILE n <= 10
        PRINT n;
        n = n + 1
    WEND
    END
    

    Example 2

    WAP to print even numbers from 1 to 20

    CLS
    n = 2
    WHILE n <= 20
        PRINT n;
        n = n + 2
    WEND
    END
    

    Example 3

    WAP to print the numbers from 20 to 1 in descending order.

     
    CLS
    n = 20
    WHILE n >= 1
        PRINT n;
        n = n - 1
    WEND
    END
    

    Example 4

    WAP to print your name 10 times

    CLS
    n = 1
    WHILE n <= 10
        PRINT "Your Name"
        n = n + 1
    WEND
    END
    

    Example 5

    WAP to print the multiplication table of given number.

    CLS
    i = 1
    INPUT "Enter any number "; n
    WHILE i <= 10
        PRINT n; "x"; i; "="; i * n
        i = i + 1
    WEND
    END
    

    232