"for" Loop Statement

This section describes what is a 'for' loop statement in H language.

A "for" loop statement is a statement that executes a sub-statement repeatedly for each element from a given array.

A "for" loop statement has the following syntax:

$for x $in array, sub-statement;

Examples of "for" loop statements are:

$for x $in array(1,2,3,4,5), write("x = "+x);

list = range(1,100);
sum = 0;
$for x $in list, sum = sum + x;

# the following loop prints the first 3 items 
# from a shopping list
$for x $in array(0,1,2), (
   item = shoppingList[x];
   write("Item "+(x+1)+": "+item);
);

Last update: 2017.

Table of Contents

 About This Book

 Introduction of H Language

 Syntax

 Data Types

 Variables

 Expressions

Statements

 What Is an Statement

 Expression Statement

 Assignment Statement

 Conditional "if" Statement

 Conditional "elseif" Statement

 Conditional "else" Statement

 Group Statement

 "while" Loop Statement

"for" Loop Statement

 Loop "break" Statement

 Loop "next" Statement

 "switch" Statement - Not Supported

 "do...while" Statement - Not Supported

 "boolean" Data Type

 "integer" Data Type

 "string" Data Type

 "real" Data Type

 "array" Data Type

 Source Code Packages

 Classes and Objects

 Object Oriented Programming

 Inheritance - Object Attachments

 Encapsulation - Private Members

 References

 PDF Printing Version