NWN2 Scripting.




Simulation Training.

Introduction
Home
First Program
Seeing Results
Variables and Data Types
Comments
Functions
Data Conversion
Random Numbers
Concatenation
Arithmetic Operators
Compound Assignments
One More or Less
Precedence
Relational Operators
The Open Branch
The Closed Branch
Logical AND
Logical OR
Compound Statements
ELSE If
Switch Case
The ? Operator
The for Loop
The while Loop
The do while Loop
Introduction to Functions
Passing Values
Passing Multiple Values
Multiple Functions
Simplifying Functions
TRUE/fALSE Conditions
Return Values
Setting Global Variables
Getting Global Variables
Setting Local Variables
Getting Local Variables
WayPoints Introduction
Static Waypoint Sets
Dynamic Waypoint Sets
Dynamic WP Cycles
Input Output

The while Loop

The while-loop is like the for-loop with the difference being in the for-loop you know the exact numer of times the loop will be repeated, but in th while0loop you do not know ahead of time how many times it will be repeated.


The while loop

The basic form of the while loop is shown below

whilte(expression)

 {

   (body of loop)

 }

An example of the use of the whie loop  is shoawn in the following program:

void main()

{

int TheTime;

string Message;

object oPC=GetEnteringObject();

 Message="Booooo!";

 TheTIme=GetTimeHour();

 while(TheTIme==12)

  {

    TheTime=GetTImeHour();

   FloatingTextStringOnCreature(Message, oPC);

  }

}

The above program checks the current game time (the game hour). If the game time is 12 (midnight) then the while-loop initiates and keeps checking the game time. As long as the game time is equal to 12, the message "Boooo!" keeps appearing. Once the game time hour is no longer equal to 12, the while-loop stops.

The table below identifies the major parts of the while loop from the program above.

From the Program while loop meaning
while Reserved word indicating the beginning of the while loop.
(TheTime==12) Expression of the while loop tested and executed if TRUE.
{ Beginning of the while loop body.
} End of the while loop body.

 


 

Where do we go from here?

The next sections will introduce the do while loop.

Nwn2Scripting provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 2008 by Adamson House, Ltd. All Rights Reserved.

Questions or Comments: EMail Webmaster

Donations are to Adamson House, Ltd who maintains this site.
All donations go the the improvement of this site.