#If I have many for loop when I defining function, and I use return true.

16 messages · Page 1 of 1 (latest)

drifting ibex
#

Will return true statement help me to leave all the statement below(if I type many code below).

So, I can immediate leave the function.

fossil driftBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

orchid ferry
#

if(p='X') is wrong

#

you're assigning it not comparing it

vague bison
#

its unreadable

#

your prof will also hate you

#

run an auto formatter over you code

#

and you will 100% not miss a point for style if that exists

drifting ibex
vague bison
#

well probably you can do better

#

if you ahve to do many ifs

mossy sequoia
#

A return statement breaks out of the function that it is inside of, regardless of how many for loops, while loops, or if statements it is within

#
void flombigate() {
    for (int x = 0; x < 10; x++) {
        for (int y = 0; y < 10; y++) {
            if (x + y > 10) {
                return; //this will return from the *function* it's in, so it will return from "flombigate", and nothing else in flombigate will get run
            }
        }
    }
}
fossil driftBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.