Pic Related is what Bjoustrop advices to do to break nested loops, thats what I am goint do

Pic Related is what Bjoustrop advices to do to break nested loops, thats what I am goint do.

Other urls found in this thread:

rustbyexample.com/flow_control/loop/nested.html
gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
twitter.com/SFWRedditVideos

Or you can just use a function find_something() and return a pointer.

This is why I stopped trying to learn Rust. No goto statements, and of course everything written about it just this religious spiel about how goto is such a bad thing that it's apparently acceptable to force everyone who might ever use your language to abide by that dogma.

Aren’t goto’s considered a bad idea and insecure? Why not just use a flag variable set flag=1, then if flag==1 break out of both loops.

cuz Bjoustrop is a brainlet who never coded something good he is just focused in promote C++

No.
goto can be useful in the right situation.

Justified use of goto.

>Aren't goto's considered a bad idea and insecure?
That's just:
>this religious spiel about how goto is such a bad thing
You're right - using a flag variable would be functionally equivalent, but there is nothing inherently insecure or "a bad idea" about using goto.
Like any other feature of the language, it's just a tool for doing something. Everything can be abused (especially with a language so powerful/complicated as C/C++) so it's the programmer's duty to use it responsibly.

the recent goto fail thing was because brainlets at apple didn't use braces in their if statements.

in my experience gotos are confusing only when going against the codeflow (i.e. up). they are awesome for cleanup and nested loops. read linux sources - gotos everywhere.

I like using unnamed lambdas and return

[&](){
//loops
if(~~~)
return;//breaks all loops dead
//
//not found
}();

Lots of retarded extra checks. If you have multiple loops, then surely that's where most of the processing time is being spent in your program.

gotos are considered bad everywhere.
why are people supporting this?
spigitty code is the oldest meme in the game

t. brainlet
Rust has these things so people like you stay away.

Tell me then why Lua has gotos and Java has reserved the goto keyword?

result_type result;

result = change_state_a();
if (is_error(result)) { goto change_state_a_failure; }

result = change_state_b();
if (is_error(result)) { goto change_state_b_failure; }

result = do(your_thing);

unchange_state_b();
change_state_b_failure:
unchange_state_a();
change_state_a_failure:
return result;

please, write it more concisely.

Gotos are and SHOULD be used in C to make exception-like behaviour. You put it at the end of the function and in case of error, you jump to it.
You can free the resources there.

This is objectively better in every way unless you're writing assembly

just avoid using gotos. They invite mistakes and a lazy style, even good programmers should avoid them. The usable cases for gotos are rare (or in some languages not existing) and should be handled by the more experienced programmers.

That is a very simple example.
In a real application, loops will rarely be that straight forward and clean, and goto just creates confusion because you can't follow normal control flow rules while reading code with a bunch of jump statements.

It all depends on how explicit your labels are

goto outside_these_3_nested_loops;
...
}//loop3
}//loop2
}//loop1
outside_these_3_nested_loops: ;

Link your git repo.

break is better than goto

But what if you need to break out of a nested loop?

I don't like it.
I feel like this use of goto is just bad practice.

There are very niche ways when it should be used, but just exiting out of loops isn't something I'd use it for.

You set a flag, break out of the inner loop, then check the flag in the outer loops.

>You set a flag, break out of the inner loop, then check the flag in the outer loops.
I'd much prefer a goto, to be honest. The intention is a lot clearer and it avoids an additional condition.

Also, if you've ever used a switch statement, you're pretty much using goto.

Why not just use break ?

Why not just implement labeled loops?

Yeah, just put in n extra checks in your n nested loops because Dijkstra wrote an opinion piece about how goto is bad literally half a century ago.

Except Rust actually has labels and you can break out of nested loops with them,.
rustbyexample.com/flow_control/loop/nested.html

Because Rust has it, so it's SJW tier babby technology that has no place in "real" programming.

you can also pu the loops in try-catch block and throw exception from it
>that's retarded
just sayin' it's an option

Java has it as well, so it's professional industry tier mature technology for _real_ programming.

>babby
baby

He's not advocating for the use of gotos, he's just providing an example of where gotos might make sense and do the least damage. Of course brainlets will use this taken out of context to bash him or C++.

...

Never use exceptions to control your program flow

What if you're used to declare the loop variables in the for-statement like for(int i = 0; ...). Will you be able to access them in the found label?

break *is* goto without label stopping just outside its current scope. if you are programming with breaks, you are programming with jumps, which means you might as well use gotos!

break will execute the 'not found' code

>brainlets can't come up with better code without using the "forbidden" word
>mindlessly bash any usage of "forbidden" word

of course not, do you even scope?

and how will you implement find_something()? remember, multiple return points are a code smell!

That's why they invented exceptions.
try {
changeStateA();
changeStateB();
return doWhatever();
}
catch (StateAException e) {
unchangeStateA();
}
catch (StateBException e) {
unchangeStateB();
}

That's literally not why they invented exceptions.

goto user here
can someone redpill me on why goto is 'insecure'?
I know they're bad for other reasons, but specifically 'insecure'? how?

In c++ you can imitate try-finally using RAII, since they apparently dont like sugar.

Yes. Isn't the proper way of breaking out of nested loops to return?

also >comment after function declaration but before definition
Do people actually do this?

sure, now try that in c.

multiple return statements? i guess you don't abide by misra?

>their brainlet poorfag jobless language doesn't have labeled loops
Java master race everyone pls do the needful and switch to Java asap

label1: for(...) {
for(...) {
...
break label1;
}
}

>you need to scroll up to see label
nigga pls, ur breaking my flow

>he doesn't write 1000+ line functions with hundreds of temp variables and flags, all crammed in a single monolithic class
You'll never find a job with that attitude

#define El int
#define ElMat El **
void
do_something(ElMat mn, int m, int n, El a, void(*something)(ElMat, int, int))
{
for (int i = 0; i != m; ++i)
for (int j = 0; j != n; ++j)
if(mn[i][j] == a) {
(*something)(mn, i, j);
return;
}
}

cause bad coders make unreadable messes by jumping randomly to places so know gotos are just considered bad. Like driving and talking on the phone, some people can manage to do both but a lot of people can't and cause accidents.

Dynamic gotos are insecure. In C, those are disallowed, but compilers implement them anyway:
gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html