Questions tagged [statements]

In computer programming a statement is the smallest standalone element of an imperative programming language. A program written in such a language is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions).

A statement is the smallest standalone element of an imperative programming language. A program written in such a language is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions).

Resources

458 questions
5
votes
1 answer

"does not name a type" error when using namespaces in c++

In the below code writing the statement A::x=5 is giving the error: 'x' in namespace 'A' does not name a type Can't we assign a value globally for x variable? #include int x = 10; namespace A { int x = 20; } A::x=5; int…
sivakrdy
  • 51
  • 1
5
votes
4 answers

What's the difference between `{}` and `()` in these code?

Destructuring_assignment#Assignment_without_declaration it says: the {a, b} on the left-hand side is considered a block and not an object literal. var a, b; {a, b} = {a:1, b:2};//Syntax Error! ({a, b} = {a:1, b:2}); // it works what the '()' do…
5
votes
5 answers

Making your own statements

Is there a way to define new statements like def, with, for of my own in Python? Of course, I don't mean to override the existing statements, only create some of my own. If so, how do I do it? Can you point me to good docs on the subject?
Guy
  • 12,478
  • 25
  • 61
  • 86
5
votes
6 answers

AND/OR (&&/||) logic for multiple condition statements

If you have an if-statement in C# that checks multiple conditions: if (a == 5 && b == 9) { ... } Does b == 9 still get checked if a == 5 condition is false, or does it automatically exit since there's no way this could pass anymore? Similarly, for…
miguelarcilla
  • 1,396
  • 1
  • 18
  • 38
5
votes
5 answers

C++ Multiple statements for conditional operator

I'm trying to use a conditional statement that does one thing in one condition but does two things if the other condition applies. Consider the following: ( h >= 0 && h < 24 ? hour = h : hour = 0, cout << "Invalid Hour Detected\n") If "h" is set…
Steve Eggering
  • 609
  • 1
  • 8
  • 21
5
votes
2 answers

Multiple IF statement conditions

I have a PHP script that runs through an array of values through my own custom function that uses the PHP function preg_match. It's looking for a match with my regular expression being $valueA, and my string to search being $valueB, and if it finds…
5
votes
2 answers

Dealing with large switch statements in CUDA

I understand that branching in CUDA is not recommended as it can adversely affect performance. In my work, I find myself having to implement large switch statements that contain upward of a few dozen cases. Does anyone have any idea how badly this…
gamerx
  • 546
  • 5
  • 14
4
votes
1 answer

Expressions and Statements in JavaScript

I just started to learn JavaScript with the book "Eloquent JavaScript", which is accessible free of charge at eloquentjavascript.net. So far I really like the book, there's just one section I don't understand. It's the one about expressions and…
lkbaerenfaenger
  • 5,652
  • 5
  • 21
  • 33
4
votes
2 answers

Does Groovy's ternary conditional operator support statements, not just expressions?

Is it possible to include statements with expressions with Groovy's conditional operator? This is what I'm doing now, and I want break this down in a single conditional statement with the println statements... if(!expired){ println 'expired is…
raffian
  • 28,859
  • 25
  • 95
  • 164
3
votes
0 answers

Is gcc wrong by allowing the code with compound statement to compile?

I'm trying to add tuple elements into a vector. The below code is working: #include #include #include #include #include template std::vector to_vector(std::tuple x) { …
João Paulo
  • 5,109
  • 3
  • 37
  • 64
3
votes
3 answers

Print a line if conditions have not been met

Hello fellow stackoverflowers, I am practising my Python with an example question given to me (actually a Google interview practice question) and ran into a problem I did not know how to a) pose properly (hence vague title), b) overcome. The…
user8226002
3
votes
1 answer

F# wrapping statements in a do block

I have a question regarding conventions on using do blocks in F#. Primarily this comes up when working with the .NET library classes and other .NET code. Let me give you an example. 1. With a do block wrapped around statements: let drawHelloName…
Overly Excessive
  • 1,955
  • 13
  • 27
2
votes
2 answers

How to access variables inside regex statements? c# 4.0

I have looked everywhere, but I cannot for the life of me figure out how to make a variable inside a regex statement be accessible from elsewhere. If someone could help that would be amazing! Here is the code: string strRegex = @"(regexstring)"; …
2
votes
0 answers

Find if the current statement in an If/Else block is the last statement of the THEN branch

I am using JavaParser to parse through the contents of the following code and identify the sequence of statements: class X { void x() { int x = 1; if (x>4) { x=21; } else { if (x>1) { x=3; } else…
John Stef
  • 541
  • 1
  • 4
  • 13
2
votes
4 answers

Transforming if-else into switch case throws error [Java]

I tried to convert my if-else statements into a switch case but I had the following problem. Old code: if (properties.get("database").toString().equalsIgnoreCase("SQLSERVER")) { manager = new CManagingSQLServer(); } else if…
41 72 6c
  • 1,243
  • 4
  • 12
  • 22
1
2
3
30 31