See more articles about "vb-script "

Beheld Basal Software Tutorials - Tutorial Addendum - Bend Statements



 31 December 18:00   

    



    

(Continued from antecedent part...)

    

Here is the output:

    

 

    

Found a prime number: 3

    

Found a prime number: 5

    

Found a prime number: 7

    

Found a prime number: 11

    

Found a prime number: 13

    

Found a prime number: 17

    

Found a prime number: 19

    

Found a prime number: 23

    

Found a prime number: 29

    



    

The achievement looks good. Some addendum about the sample script:

    



        

  • Nested loops, one bend central addition loop, are used.


  •     

  • The alien bend goes through integers amid 3 and 20, and skips even numbers with "Step 2"


  •     

  • The close bend goes determines if the accepted accumulation "i" is a prime or not


  •     

  • The close bend has a codicillary "Exit For" account to abolish the bend as anon as

        

    "i" has been bent as a non-prime number.



  •     



    



    



    

"While" Statements

    

Another blazon of bend statements is alleged "While" statement, which has the afterward syntax:

    



    

While condition

    

statement_block (multiple statements)

    

Wend

    



    

where "condition" is a Boolean value.

    

The way a "While" account is accomplished looks like:

    

Step 1: Analysis Boolean amount of "condition".

    

Step 2: If the accepted amount of "condition" is "True", abide with Move 4.

    

Step 3: If the accepted amount of "condition" is "False", abolish the loop.

    

Step 4: Assassinate "statement_block" amid in the "While ... Wend" loop.

    

Step 5: Abide with Move 1.

    

The argumentation of a "While" account is simpler than a "For ... Next" statement. But you accept to manage

    

the action carefully, so that its amount will become "False" at some point to abolish the loop.

    

Notice that there assume to be no "Exit" account to breach "While" bend early.

    



    

"While" Account Example

    

To advice you accept how "While" statements work, I wrote the afterward the example, loop_while.html:

    

 

    

<html>

    

<body>

    

<!-- loop_while.html

    

Absorb (c) 2006 by Dr. Yang. http://www.yang.com/

    

-->

    

<pre>

    

<script language="vbscript">

    

document.writeln("")

    

i = 3

    

While i <= 30

    

bIsPrime = True

    

j = 2

    

While j <= i2 And bIsPrime

    

bIsPrime = i Mod j > 0

    

j = j + 1

    

Boat

    

If bIsPrime Then

    

document.writeln("Found a prime number: " & i)

    

End If

    

i = i + 2

    

Wend

    

</script>

    

</pre>

    

</body>

    

</html>

    



    

Here is the output:

    

 

    

Found a prime number: 3

    

Found a prime number: 5

    

Found a prime number: 7

    

Found a prime number: 11

    

Found a prime number: 13

    

Found a prime number: 17

    

Found a prime number: 19

    

Found a prime number: 23

    

Found a prime number: 29

    



    

The archetype formed perfectly. What do you think?

    

(Continued on next part...)

    



    



    



 


 prime, statement, condition, value, statements, bisprime, script, terminate, current, output, found, notes, , prime number, terminate the, loop statements, prime number 17found, prime number 13found, prime number 11found, prime number 19found, prime number 23found, loop while html, prime number 29the, prime number 7found, prime number 5found, script tutorials tutorial, basic script tutorials, tutorials tutorial notes, tutorial notes loop, prime number 3found, notes loop statements, visual basic script,

Share Beheld Basal Software Tutorials - Tutorial Addendum - Bend Statements:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Beheld Basal Software Tutorials - Tutorial Addendum - Bend Statements
(Continued from antecedent part...)"Do ... Loop" StatementsPersonally, I anticipate that two types of loops, "For ... Next" and "While", are abundant for any bend programming situations. But t

Beheld Basal Software Tutorials - Tutorial Addendum - Numeric Operations
This affiliate describes:Long Accumulation OperationsDouble Amphibian Amount OperationsNumeric Operations on Additional Data TypesNotes and samples in t

Beheld Basal Software Tutorials - Tutorial Addendum - Numeric Operations
(Continued from antecedent part...)Double Amphibian Amount OperationsDouble amphibian amount operations are algebraic operations that: Operates on two bifold amphibian am

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
This affiliate describes:What Is a Procedure?Defining and Invoking Action ProceduresFunction Action ExampleDefining and Invoking Sub ProceduresSub Action

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
(Continued from antecedent part...)Function Action ExampleTo advice you accept the abstraction of action procedure, I wrote the afterward the example, function_f2c.html: <

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
(Continued from antecedent part...)Sub Action ExampleHere is a abbreviate archetype of subroutines, function_sub.html: <html><body><! function

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
(Continued from antecedent part...)Example Casual Arguments by ReferenceTo see how casual arguments by advertence works, I wrote the afterward example, function_swap_by_ref.html:

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
(Continued from antecedent part...)Here is the output: Test 1: Swapping two literals by value Afore Sub: Angel Orange In Sub: Orange Apple Afterwards Sub: Angel Orange

Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
(Continuedfrompreviouspart...)VariableScopeinProceduresVariableScope Theareaofsourcecodewhereavariableisaccessible.Ifyouarenotusingprocedures,variablescopeisverysimple.Thescope

Beheld Basal Software Tutorials - Tutorial Addendum - Variables - Acknowledgment and Appointment
This affiliate describes:Variable DeclarationAssigning Ethics to VariablesVariable Absence ValuesVariable Declaration