So what does this mean ? return answer[0] == y; I am not entirely sure of its meaning any help is appreciated
return statement tells a function to return execution of the program to the calling function, and report the value.
return
In your situation the return value will be either true or false.
true
false
Think of it like this in pseudo-code:
return (is the answer equal to y) //yes = true; no = false
then you can break it down:
return (the answer equal to y) return (answer[0] equal to y) return answer[0] == y
Most logic is done through conditional statements. Something that can be seemingly perplexing at first, but consider a switch statement:
switch(value) { case 1: dosomething(); break; case 2: dosomethingelse(); break; default: donothing(); break; }
is the same as if value == 1, if value ==2, if value == 3
If statements are the same if(10 > 5) dosomething(); // is 10 greater than 5? true
Even these are implementations of conditional statements:
return x == 5 ? x : 0; // if x is equal to 5 send back x; if x is NOT equal to 5 send back 0
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
return
statement tells a function to return execution of the program to the calling function, and report the value.In your situation the return value will be either
true
orfalse
.Think of it like this in pseudo-code:
return (is the answer equal to y) //yes = true; no = false
then you can break it down:
return (the answer equal to y)
return (answer[0] equal to y)
return answer[0] == y
Most logic is done through conditional statements. Something that can be seemingly perplexing at first, but consider a switch statement:
switch(value)
{
case 1:
dosomething();
break;
case 2:
dosomethingelse();
break;
default:
donothing();
break;
}
is the same as if value == 1, if value ==2, if value == 3
If statements are the same if(10 > 5) dosomething(); // is 10 greater than 5? true
Even these are implementations of conditional statements:
return x == 5 ? x : 0; // if x is equal to 5 send back x; if x is NOT equal to 5 send back 0