Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

all
function
array
d
communitycreator

How to use the all() method in D

Theodore Kelechukwu Onyejiaku

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.stdio
import std.stdio; 
import std.algorithm;
 
// The main method
void main(string[] args) { 
  // Create an array
  int[] array1 = [50, 20, 10, 45, 34];
  int[] array2 = [0, 1, 2, 3];
  string[] array3 = [""];

  // Check if the elements are true
  writeln(all(array1)); // true
  writeln(all(array2)); // false
  writeln(all(array2)); // false
}
Checking if the elements of an array are true

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.

RELATED TAGS

all
function
array
d
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku
RELATED COURSES

View all Courses

Keep Exploring