flow-control

Flow controlling macros with 'goto'

Yes, two hated constructs combined. Is it as bad as it sounds or can it be seen as a good way to control usage of goto and also provide a reasonable cleanup strategy? At work we had a discussion about whether or not to allow goto in our coding standard. In general nobody wanted to allow free usage of goto but some were positive about us...

What is a good local heuristic for dynamic discrete node flow control?

Suppose you have a set of nodes. Some nodes are producers, some are consumers, and some are routers. Each node has a maximum throughput which defines the maximum number of units it can accept per day, and also the maximum number of units it can send per day (in this case accepts and sends do not interfere with each other). Each node also...

Can XON and XOFF be equal?

Can the application use set same char in the XON and XOFF? If yes, how my device driver should handle this situation ...

Need help parsing results from ldap to csv

Hi, I am trying to create a script to generate a csv file with the results of some ldap queries using Net::LDAP but I'm having troubles skipping incomplete lines if one element of the @attributes array is blank. my @attributes = ('cn', 'mail', 'telephoneNumber'); So for example, if a user has no mail listed, or no telephoneNumber li...

Stop execution of a script called with execfile

Is it possible to break the execution of a Python script called with the execfile function without using an if/else statement? I've tried exit(), but it doesn't allow main.py to finish. # main.py print "Main starting" execfile("script.py") print "This should print" # script.py print "Script starting" a = False if a == False: # Sa...

How to implement a do-while loop in tsql

I'm trying to figure how to implement this in TSQL do update stuff set col = 'blah' where that_row = 'the right one' select trash from stuff ... until some_condition The only iterative control flow sentence provided by Transact-SQL is while (condition) sentences that first evaluates the condition and if that condition is true the...

Why does else behave differently in for/while statements as opposed to if/try statements?

I have recently stumbled over a seeming inconsistency in Python's way of dealing with else clauses in different compound statements. Since Python is so well designed, I'm sure that there is a good explanation, but I can't think of it. Consider the following: if condition: do_something() else: do_something_else() Here, do_someth...

SQL Server 2000: How to exit a stored procedure?

How can i exit in the middle of a stored procedure? i have a stored procedure where i want to bail out early (while trying to debug it). i've tried calling RETURN and RAISERROR, and the sp keeps on running: CREATE PROCEDURE dbo.Archive_Session @SessionGUID uniqueidentifier AS print 'before raiserror' raiserror('this is a raised error'...

How can I execute several maven plugins within a single phase and set their respective execution order?

Hi all, I would like to breakup certain phases in the maven life cycle into sub phases. I would like to control the execution flow from one sub-phase to another, sort of like with ant dependencies. For example, I would like to use the NSIS plugin in order to package up my project into an installer at the package stage, AFTER my project...

Exiting from the Middle of an Expression Without Using Exceptions

Solved: I figured out a clean way to do it with setjmp()/longjmp(), requiring only a minimal wrapper like: int jump(jmp_buf j, int i) { longjmp(j, i); return 0; } This allows jump() to be used in conditional expressions. So now the code: if (A == 0) return; output << "Nonzero.\n"; Is correctly translated to: return ((A == 0) && ju...

Java Flow Control Problem

I am programming a simple 2d game engine. I've decided how I'd like the engine to function: it will be composed of objects containing "events" that my main game loop will trigger when appropriate. A little more about the structure: Every GameObject has an updateEvent method. objectList is a list of all the objects that will receive upd...

Do Perl loop labels count as a GOTO?

Generally, it is good practice to avoid GOTOs. Keeping that in mind I've been having a debate with a coworker over this topic. Consider the following code: Line: while( <> ) { next Line if (insert logic); } Does using a loop label count as a goto? Here is what perlsyn in perldoc has to say: Here's how a C progra...

how to combine switch and if else statements

I'm taking an online java class and the teacher has asked for the following: Write a menu program that ask a user for a number indicating the four basic math equations(addition, subtraction, multiplication, division). Using a if/else structure to do the required operation, ask the user for inputs and solve the equation. I am new to this,...

Perl elsif not being evaulated

Anyone see anything wrong with this code? When we execute it (on Linux), we get taken straight to the "Error: Unknown host" block. Perl is version 5.8.6 $hostname = "host2"; if ($hostname eq "host1") { $dbhost = 'dbi:Oracle:dbhost1'; } elsif ($hostname eq "host2") { $dbhost = 'dbi:Oracle:dbhost2'; } elsif ($hostname eq "host3" |...

python try/finally for flow control

I'm sure this concept has come up before but I can't find a good, simple answer. Is using try/finally a bad way to handle functions with multiple returns? For example I have try: if x: return update(1) else: return update(2) finally: notifyUpdated() This just seems nicer than storing update() commands in...

How do I break an outer loop from an inner one in Perl?

Suppose I have a piece of Perl code like: foreach my $x (@x) { foreach my $y (@z) { foreach my $z (@z) { if (something()) { // I want to break free! } // do stuff } // do stuff } // do stuff } If something() is true, I would like to break ('last') all the loops. how can I do that? I thought of two options, bot...

Syntax or construct to simplify if() statement?

I'm looking for a semantic or language construct that will simplify some of my if statements. If I have an if statement with an or, where I 'choose' between two values, I'd like to have that chosen variable available later on in the code. I'll write this in pseudo-code: if ( x or y ) { function(z); } Where z is the value of x o...

Controlling flow in ASP.NET with return;, don't render the rest of the page.

Hello, this question should be fairly basic. I want to control the flow of an ASP.NET page -- if a certain condition is met, I want to write out an error message and stop drawing the page. However, I also want ASP.NET to output correct HTML (i.e. not cut off in the middle). Right now I am doing this: if (condition != what-i-want) { ...