Questions tagged [control-structure]

Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed.

Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed.

The kinds of control flow statements supported by different languages vary, but can be categorized by their effect:

  • continuation at a different statement (unconditional branch or jump),
  • executing a set of statements only if some condition is met (choice - i.e., conditional branch),
  • executing a set of statements zero or more times, until some condition is met (i.e., loop the same as conditional branch),
  • executing a set of distant statements, after which the flow of control usually returns (subroutines, coroutines, and continuations),
  • stopping the program, preventing any further execution (unconditional halt).

from Wikipedia

138 questions
0
votes
5 answers

What are the downsides to defining a C macro that works like the Python "with" statement?

After playing around a bit with C preprocessors, I thought of a way to have something similar to a Pythonian with control structure, defined like this: #define with(var) for(int…
ConsciousCode
  • 563
  • 4
  • 18
0
votes
1 answer

How can this PHP logic control structure be refactored?

My gut tells me that there is a better, perhaps one-line refactor for the following code: if (isset($x)) { if (isset($y)) { $z = array_merge($x,$y); } else { $z = $x; } } else { $z = $y; } If I wasn't…
pbarney
  • 2,529
  • 4
  • 35
  • 49
0
votes
3 answers

PHP cache structure (skip code block if HIT)

Basically, I am implementing own cache system. Ideally, it'll look like this: $CACHE->start($name); //CODE $CACHE->end(); But that is a holy grail that I do not hope to find. Basically, the $CACHE->start() checks if cache is a hit or a miss, and…
Rok Kralj
  • 46,826
  • 10
  • 71
  • 80
0
votes
2 answers

Defining variables in control structures

According to the standard, what is the difference in behavior between declaring variables in control structures versus declaring variables elsewhere? I can't seem to find any mention of it. If what I'm referring to isn't clear, here's an…
Collin Dauphinee
  • 13,664
  • 1
  • 40
  • 71
0
votes
2 answers

How to make simple number identification Python?

I have this exercise: Receive 10 integers using input (one at a time). Tells how many numbers are positive, negative and how many are equal to zero. Print the number of positive numbers on one line, negative numbers on the next, and zeros on the…
0
votes
1 answer

Check for correct user input without exiting loop

I'm trying to write a travel itinerary program using base Python functionality. In step 1, the program should ask for primary customer (making the booking) details viz name and phone number. I've written code to also handle errors like non-alphabet…
Cat_Dog
  • 43
  • 7
0
votes
0 answers

Java check if a position @array has a value or not

hi i am sitting on a small library book exchange program in Java i want to understand programming a little more so my question is i have this now (buchRegal[0] == "" && buchregal_id[0] == null) buchRegal[0] is a position from a String array and…
0
votes
1 answer

ERROR PHP "Blank line found at end of control structure"

I made a simple, posting system. But on the if isset i made it, keeps saying Blank line found at end of control structure But i really cant find the solution and already tried many options, like moving the closing brace etc. The error is on line…
Jean
  • 49
  • 8
0
votes
1 answer

In r, how would you code to get a value based on the combinations of two binned value?

I want to Calculate median pop density for every possible combination of temp and precipitation values. For example, the pop density for places that have: Mean annual temp of 4 to 6 C and 500 to 510 mm precip Mean annual temp of 4 to 6 C and 510 to…
0
votes
1 answer

Why is it removing the 0 in the end?

So, we made this in our first semester. Why is it removing the 0 in the end? And how do I fix it? I input 4000 and it showed me 4, when I needed is 4 0 0 0. Same if I input 8030, it outputs 8 0 3. if (number > 0) { while (number != 0) { …
Angel
  • 3
  • 3
0
votes
1 answer

How do you set up an infinite loop in scanners?

I'm a beginner in Java, so I had a question on this I'm trying to create a simple code in which I'm done with it, just I wanted to know how do you set up an infinitely asking question that the user can input? The one I have right now does an…
0
votes
3 answers

Lucky number with User Input

I'm facing troubles solving the following question: I suppose to get the user to input a number and check if it is a lucky number. A lucky number is the sum of squares of even-positioned digit (starting from the second position) is a multiple of…
Wilson Soo
  • 11
  • 1
  • 1
0
votes
4 answers

Try-Catch vs If-Else | Should I fight to use If-Else in this or just go with the Try-Catch?

Summary I've been given a task to set up a management software (For a small scale artist, so their hardware can definitely cope), however, I would prefer to make this as efficient as possible before giving it to them. The main functionality is…
John Smith
  • 97
  • 9
0
votes
1 answer

large letter outline stroke with sass

I have been using the text shadow trick of using a large text shadow to create the illusion of a larger stroke width for a letter outline. It works as is for my needs but I recently started using sass and was wondering if it was possible to convert…
Marcus Ruddick
  • 9,795
  • 7
  • 28
  • 43
0
votes
2 answers

Splitting up text file into pieces, then searching key phrases in those sections

I am new to Python and I am already a fan of the language. I have a program that does the following: Opens a text file that has sections of text separated by asterisks (***) Uses the split() function to split up this text file into sections…