How to use the all() method in D
Overview
The all() method in D evaluates if all the elements of an array are true. It returns true if all values are true. Otherwise, it returns false.
Syntax
all(array)
Parameters
array: This is the array we want to check.
Return value
This method returns a Boolean value. If all the elements are true, it returns a true value. Otherwise, it returns a false value.
Code example
// Import std.stdioimport std.stdio;import std.algorithm;// The main methodvoid main(string[] args) {// Create an arrayint[] array1 = [50, 20, 10, 45, 34];int[] array2 = [0, 1, 2, 3];string[] array3 = [""];// Check if the elements are truewriteln(all(array1)); // truewriteln(all(array2)); // falsewriteln(all(array2)); // false}
Explanation
- Lines 8 to 10: We create some arrays.
- Lines 13 to 15: We check if the elements in the arrays are true. Then, we print the values to the console.