Table of Contents

ForLoopRuleset<TOperand> Class

Definition

Namespace
Cuemon.Threading
Assemblies
Cuemon.Threading.dll
Source
src/Cuemon.Threading/ForLoopRuleset.cs

Specifies the rules of a for-loop control flow statement.

public class ForLoopRuleset<TOperand> where TOperand : struct, IComparable<TOperand>, IEquatable<TOperand>, IConvertible

Type Parameters

TOperand

The type of the number used with the loop control variable.

Inheritance
ForLoopRuleset<TOperand>

Examples

The following example demonstrates how to define a for-loop ruleset using ForLoopRuleset with configurable start, end, step, relational operator, and assignment operator.

using System;
using System.Collections.Generic;
using Cuemon;
using Cuemon.Threading;

namespace Contoso.Scheduling;

public sealed class ForLoopRulesetExample
{
    public static void Run()
    {
        var rules = new ForLoopRuleset<int>(
            from: 0,
            to: 5,
            step: 1,
            relation: RelationalOperator.LessThanOrEqual,
            assignment: AssignmentOperator.Addition);

        var values = new List<int>();
        int current = rules.From;

        while (rules.Condition(current, rules.Relation, rules.To))
        {
            values.Add(current);
            current = rules.Iterator(current, rules.Assignment, rules.Step);
        }

        Console.WriteLine(string.Join(", ", values));
    }
}

Constructors

Name Description
ForLoopRuleset()

Initializes a new instance of the ForLoopRuleset<TOperand> class.

ForLoopRuleset(TOperand, TOperand, TOperand, RelationalOperator, AssignmentOperator, Func<TOperand, RelationalOperator, TOperand, bool>, Func<TOperand, AssignmentOperator, TOperand, TOperand>)

Initializes a new instance of the ForLoopRuleset<TOperand> class.

Properties

Name Description
Assignment

Gets or sets the assignment statement of the loop control variable using Step.

Condition

Gets or sets the function delegate of a for-condition.

From

Gets or sets the initial value of the loop control variable.

Iterator

Gets or sets the function delegate of a for-iterator.

Relation

Gets or sets the relation between the loop control variable From and To.

Step

Gets or sets the number to assign the loop control variable.

To

Gets or sets the conditional value of the loop control variable.