Open In App

Julia | checkbounds() function with examples

Last Updated : 06 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The checkbounds() is an inbuilt function in julia which is used to return true if the given index value lies within the bounds of the given array, otherwise returns false.

Syntax: checkbounds(Bool, Array, Index)

Parameters: This function accepts three parameters which are illustrated below:-

  • Bool: This says that this function will return boolean values as output.
  • Array: It is the given array with bounds
  • Index: It is the index value which is going to be calculated either it lies in the array bounds or not.

Returns: It returns the value true if the index value lies in the array bounds else false.

Below are some codes which illustrate the above function:
Example #1:




# Julia Program for illustration of
# checkbounds() function
  
# Initializing an array from 1 to 10
A = rand(1, 10);
  
# Initializing a index value of 5
Index = 5
  
# Calling the checkbounds() function
A = checkbounds(Bool, A, Index)
  
# Getting the value true or false
println(A)


Output:

true

Example #2:




# Julia Program for illustration of
# checkbounds() function
  
# Initializing a range from 1 to 10
A = rand(1, 10);
  
# Initializing a index value of 15
Index = 15
  
# Calling the checkbounds() function
A = checkbounds(Bool, A, Index)
  
# Getting the value true or false
println(A)


Output:

false

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads