A control structure is a statement that changes the control flow in a program, based on the evaluation of one or more conditions. Common examples include the 'if-then-else' statement, the 'case-switch' statement, 'for' loops, and 'while' loops.

learn more… | top users | synonyms

0
votes
1answer
120 views

How to choose between different ways to write some code?

I would like to validate point in a two-dimensional rectangular Cartesian coordinate. I found following regular expression solution on stackoverflow ^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$ . Another ...
7
votes
1answer
408 views

Why does Scala have return but not break and continue

Scala does not have break or continue, so some loop behavior takes a bit more of thinking. Ending a loop early requires tail recursion, exceptions, or scala.util.control.Breaks (which uses ...
8
votes
1answer
257 views

Is this a valid design pattern for a Haskell main function?

After developing several Haskell applications I've found myself rigorously segregating impure code and failable (partial) functions from their pure & total counterparts. These efforts have ...
4
votes
2answers
363 views

Why do some programming languages have break statements, but not higher-order break statements? [closed]

I may have been exposed to exactly the wrong languages, but though many have loops and break statements, none of the languages I am familiar with have higher-order break statements¹. While a regular ...
7
votes
2answers
1k views

“Proceed if true” vs “stop if false” in if statements [duplicate]

While I was writing a private helper method in Java, I needed to add a check for a precondition that would cause the method to do nothing if not met. The last few lines of the method were just off the ...
1
vote
2answers
169 views

In an if statement, what are an “if clause” and a “then clause”?

I am a bit confused about the nomenclature for the parts of an if statement. Consider the following example: 1: if condition then 2: statement_1; 3: else 4: statement_2; 5: end if; ...
-4
votes
2answers
66 views

what is a basic block called if it contains a branch instruction? [closed]

what is a basic block called if it contains a branch instruction? How about a block that does not contain a branch instruction? Thanks,
2
votes
3answers
215 views

Conditional construct for a kleenean data type

I was thinking of an hypothetical programming language with a kleenean data type which would implement Kleene's three-valued logic. To sum up, it's an extension of the boolean data type with the three ...
6
votes
3answers
1k views

Why was GOTO included in PHP 5? [closed]

I discovered some time ago that the GOTO control keyword was introduced in PHP 5.3.0. http://php.net/manual/en/control-structures.goto.php Why did it happen? What are the language design goals ...
6
votes
5answers
320 views

design for interruptable operations

I couldn't find a better topic but here it is; 1) When user clicks a button, code starts t work, 2) When another button is clicked, it would stop doing whatever it does and start to run the second ...
15
votes
8answers
3k views

Why does Clang/LLVM warn me about using default in a switch statement where all enumerated cases are covered?

Consider the following enum and switch statement: typedef enum { MaskValueUno, MaskValueDos } testingMask; void myFunction(testingMask theMask) { switch theMask { case ...
4
votes
2answers
236 views

Is it dangerous for me to give some of my Model classes Control-like methods?

In my personal project I have tried to stick to MVC, but I've also been made aware that sticking to MVC too tightly can be a bad thing as it makes writing awkward and forces the flow of the program in ...
4
votes
4answers
573 views

Is it bad practice for a module to contain more information than it needs?

I just wanted to ask for your opinion on a situation that occurs sometimes and which I don't know what would be the most elegant way to solve it. Here it goes: We have module A which reads an entry ...
18
votes
10answers
5k views

Do we still have a case against the goto statement? [duplicate]

Possible Duplicate: Is it ever worthwhile using goto? In a recent article, Andrew Koenig writes: When asked why goto statements are harmful, most programmers will say something like ...
542
votes
22answers
54k views

Where did the notion of “one return only” come from?

I often talk to Java programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's ...
31
votes
5answers
2k views

Why are brackets required for try-catch?

In various languages (Java at least, think also C#?) you can do things like if( condition ) singleStatement; while( condition ) singleStatement; for( var; condition; increment ) ...
0
votes
9answers
4k views

Loops in real-life problems

I'm learning C as my first programming language. I'm confused on how do loops work in real-life. In programming every function has a reason. example - if/else statements are used if we have ...
73
votes
19answers
27k views

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) ...
12
votes
22answers
1k views

Which useful alternative control structures do you know? [closed]

Similar question was closed on SO. Sometimes when we're programming, we find that some particular control structure would be very useful to us, but is not directly available in our programming ...