In code, how can I look into an array of n amount of elements and make sure that there is no 0s at all within said array. Here is the code I am working on to check for the array’s content:
private bool validate()
{
for (int i = 0; i < myArray.Length; i++)
{
if (myArray *> 0)*
return true; } return false; } Can anyone tell me what I am doing wrong and how can I fix it? Many thanks in advance.
You’re exiting the function after the first correct element.
What you want to do, is reverse the logic. So that you immediately return false if you find one that’s equal to zero, but continue throughout the entire for loop if you’re getting correct elements:
private bool validate()
{
for (int i = 0; i < myArray.Length; i++)
{
if (myArray *<= 0)*