Skip to main content

Questions tagged [control-structures]

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.

-2 votes
4 answers
274 views

Programming languages traditionally have blocks that specifically cater to controlling iteration. There is the simple while-loop: while (i < 3) {...}; Then there is the more complicated for-loop: ...
Steve's user avatar
  • 12.7k
0 votes
2 answers
774 views

I am writing some code that enables / disables a certain kind of hardware function. To enable it on, I have to call some methods, and to disable it, some others. Of course I want this code to be clean,...
Bart Friederichs's user avatar
0 votes
0 answers
90 views

Not many architectures have skip instructions today. They are (usually) conditional instructions that skip the following instruction. A few architectures having these: PIC14, with its btfss and btfsc ...
Omar and Lorraine's user avatar
3 votes
2 answers
1k views

When it comes to name things like if, else, or return, many developers and a lot of documentation calls it control flow or control flow statements. https://docs.oracle.com/javase/tutorial/java/...
john c. j.'s user avatar
1 vote
3 answers
271 views

The following code works and is clear, but it's also verbose. I suspect that there's a way to make it more terse, so that it could be skimmed quickly and it'd be more obvious what's happening. // The ...
Ian Dunn's user avatar
  • 125
3 votes
1 answer
167 views

I want to choose between several options, and if the criteria I'm using for selection happen to be equal, I want one at random (reasonably so, so it's equal-chance each time, rather than arbitrary). ...
mattdm's user avatar
  • 149
2 votes
4 answers
253 views

In our project there are deep and lengthy if-else structures which can be significantly shortened by a simple rearrangement. To me the shorter version would be easier to understand also. As an ...
riskop's user avatar
  • 129
-1 votes
1 answer
83 views

The scenario is as follows. There is a PC running a complex piece of AI software wirelessly controlling a number of soccer robots. This software is written and maintained by a team of students that ...
Pepijn's user avatar
  • 337
0 votes
3 answers
580 views

Basically, I want to know how to simulate while and if if I'm handling the control flow myself through an array of instructions. The while loop can be simulated by if, as seen with assembly branching ...
Lance Pollard's user avatar
3 votes
3 answers
413 views

I started out with the following, simple routine: void originalCode(){ boolean status = getStatus(); function2(status); if(status){ return; } function3(); } But ...
executor21's user avatar
4 votes
4 answers
170 views

Been given an awkward design challenge, and I'm not sure how best to handle it. The scenario is this: in the system there's a concept of "Client". Each client has various bits of supporting metadata ...
Bob Tway's user avatar
  • 3,646
2 votes
2 answers
231 views

while cond1 ... if cond2 ... else ... break The while loop above has two termination conditions, cond2 and !cond1 !cond2 When the commands that are represented by ....
Tim's user avatar
  • 5,565
2 votes
2 answers
103 views

Inside our UI there's an option to select something from a dropdown. Depending on what you choose inside that menu the rest of the fields inside the UI change accordingly. At the moment we handle it ...
cgew85's user avatar
  • 123
5 votes
4 answers
542 views

Something that often comes up in code reviews is the structure of the code, particularly related to the use of control structures, where individuals can be fairly opinionated on what is "right" and ...
Baldrickk's user avatar
  • 734
5 votes
6 answers
5k views

I've been set a challenge that I'm trying to get my head around, but am struggling with the best (or 'correct') way to implement it. The challenge is to create a simple console app written in Go that ...
Hexodus's user avatar
  • 77

15 30 50 per page