Loop "break" Statement

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

A loop "break" statement is a statement that terminates a loop early before it reaches end of the loop condition.

When a loop "break" statement is executed, the execution will be transferred to the end of the loop immediately.

A loop "break" statement has the following syntax:

loop (
   ...;
   $break;
   ...;
);

Examples of loop "break" statements are:

# the follow code runs a loop to check  
# if a given number is a prime number
x = 6789;

isPrime = $true;
i = 2;
$while i < x, (
   isPrime = x % i > 0;
   $if !isPrime, $break; # stop the loop
);

$if isPrime, write("x is a prime number.");
$else, write("x is not a prime number.");

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

 Full Version in PDF/ePUB