.CRML.ETL.Utilities.firstTrueIndex

Returns the index of the first true element of a Boolean vector

Information

Syntax

firstTrueIndex(b);

Description

Returns the index of the first true element of the Boolean vector b. If no element is true or b is an empty vector (i.e., size(b,1)=0) the function returns 0.

Example

  Boolean b1[3] = {false, false, false};
  Boolean b2[3] = {false, true, false};
  Boolean b3[4] = {false, true, false, true};
  Integer r1, r2, r3;
algorithm
  r1 = firstTrueIndex(b1);  // r1 = 0
  r2 = firstTrueIndex(b2);  // r2 = 2

r3 = firstTrueIndex(b3); // r3 = 2


The property is also demonstrated with the following example calling the function as:

Integer firstTrueIndexOutput = firstTrueIndex(b)

results in


See also

allTrue, anyTrue, countTrue, enumerate, index, and oneTrue.

Interface

function firstTrueIndex
  extends Modelica.Icons.Function;
  input Boolean b[:];
  input Boolean reverse = false "If true, backward scanning";
  output Integer index;
end firstTrueIndex;

Generated at 2026-04-01T18:18:38Z by OpenModelicaOpenModelica 1.26.3 using GenerateDoc.mos