Sambar Server Documentation

CScript While Loops


The while loop repeats a statement until the conditional test at the top proves false. The general form of a while statement is:
while ( expression ) statement
Because the expression is tested before the statement is executed, the statement part can be executed zero times. The following example returns the length of a string.
string_length(string) { int i = 0; if (string != NULL) { while (string[i] != '\0') i++; } return(i); }

The while loop is used to look at the characters in the string one at a time until the NULL character is found. Then the loop is exited and the length is returned.

© 2001 Sambar Technologies. All rights reserved. Terms of Use.