RETURN

So what does this mean ?
return answer[0] == y;
I am not entirely sure of its meaning any help is appreciated

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 or false.

  • slook26slook26 Utah
    edited June 2016

    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

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion