![]() |
![]()
| ![]() |
![]()
NAMEforeach - foreach loop in Ch SYNTAXforeach (token; expr1; expr2; expr3)
foreach (token; expr1; expr2)
foreach (token; expr1)
DESCRIPTIONThe foreach loop is used to handle iterations based on the condition of string type or pointer to char. The expressions expr1, expr2, and expr3 shall have string type or pointer to char. The identifier token also shall have string type or pointer to char. In each iteration, the variable token takes a token from the original expression expr1 separated by the delimiter expr3. The loop body is executed repeatedly until token is a NULL pointer or the same as expr2. This is achieved by comparing the controlling expression (token==NULL || expr2!=NULL && !strcmp(token,expr2)) to 0. The omitted expr2 and expr3 are replaced by NULL and " ;", respectively. EXAMPLESThe following code
gives the output of
In this example, the delimiters for token are characters of blank space and colon as shown in the value for the variable delimit in the program. The code below will create three directories dir1, dir2, and dir3 in the current directory.
FILES
SEE ALSO$CHHOME/docs/chguide.pdf AUTHORHarry H. Cheng
|