control-structure

Does the last element in a loop deserve a separate treatment?

When reviewing, I sometimes encounter this kind of loop: i = begin while ( i != end ) { // ... do stuff if ( i == end-1 (the one-but-last element) ) { ... do other stuff } increment i } Then I ask the question: would you write this? i = begin mid = ( end - begin ) / 2 // (the middle element) while ( i != end ) {...

Correct order for control structure logic (true/false, false/true)?

I am new to programming, and am wondering if there is a correct way to order your control structure logic. It seems more natural to check for the most likely case first, but I have the feeling that some control structures won't work unless they check everything that's false to arrive at something that's true (logical deduction?) It wou...

Lookup table in Latex

Hi! I have a bunch of automatically generated LaTeX code with hypertargets of the form "functionname_2093840289fad1337", i.e the name of a function with a hash appended. I would like to refer to those functions from the rest of the document by only referring to the function name which I know is unique. I would like a lookup function som...

PHP Control Structure :Declare()

I'm having a hard time understanding the PHP control structure declare() and where/how it would be used. http://us.php.net/manual/en/control-structures.declare.php I was hoping someone could explain this to me. Thank you in advance. ...

control structures - common applications

What are the most common applications of each control structure. I am trying to get at a reference along the lines of: Control Structure - common application Conditions - true / false distinction Selections - case differentiation of a few known values Loops - writing to / reading from lists do while ...

Strange PHP syntax

I've been working on PHP for some time but today when I saw this it came as new to me: if(preg_match('/foo.*bar/','foo is a bar')): echo 'success '; echo 'foo comes before bar'; endif; To my surprise it also runs without error. Can anyone enlighten me? Thanks to all :) ...

Custom control structures in Scala?

There are a number of times I've run into a simple pattern when programming in Java or C++ for which a custom control structure could reduce the boilerplate within my code. It goes something like: if( Predicate ){ Action return Value } that is, a "return if"-type statement. I've tried making functions with signature lik...

Smalltalk Variadic functions

Does Smalltalk(especially Squeak/Pharo) have some form of variadic functions? I was just reading about the power of designing your own control statments in smalltalk and while I'm a big fan of ifTrue: ifFalse: I was having a hard time coming up with a good way to implement arbitrary if,if else, if else,...,else statements thinking how u...