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
-2
votes
2 answers

Structuring if statements properly

I'm in a intro to C programming class, and I'm working on a homework assignment. I just can't get to work properly. This is the homework assignment: When someone buys a small number of widgets, they pay normal price. When someone buys a medium…
staringblind
  • 7
  • 1
  • 3
-2
votes
4 answers

Where is my code going wrong?

EDIT: I think I copied slightly wrong code! public class GradeCalculator { public static void calculateGrade(int mark) { if (mark >= 70) System.out.println("grade = A"); if (mark >= 60) System.out.println("grade = B"); if (mark >= 50)…
mark e
  • 1
  • 1
-2
votes
1 answer

SQL Alter an value from 1 to 0

Hey im looking for a SQL statement that let me alters the int in the database to a zero for inactive - i have no idea how to write the SQL query like that,and how the php code would look. This is my best guess.. select id,active from posts where…
-3
votes
2 answers

Python - elif syntax error- Whats wrong with this?

I'm trying to write a function that takes in a list and returns true if it contains the numbers 0,0,7 in that order. When I run this code: def prob11(abc): if 7 and 0 and 0 not in abc: return False x = abc.index(0) elif 7 and 0…
MNIShaurya
  • 111
  • 5
-3
votes
1 answer

Does the if sentence on python execute only once?

im new on this, and im using an if statement to load an image in case X thing happens, this is my code: if self.puntos > 0: self.fondo = load_image('Fondo2.png', IMG_DIR) self.primera_vez = True So when puntos (points) get over 0…
MrBean
  • 1
  • 3
-3
votes
1 answer

Simplify Javascript Variables to Single Statement?

Wondering if it's possible to simplify the following into one variable definition: var gpaEarned = '%%PATTERN:gpa%%'; //value for gpa is passed in dynamically var gpa = gpaEarned.replace("Less than…
adam
  • 11
  • 5
-3
votes
5 answers

Nesting if statements in python

So I am getting an invalid syntax error when trying to run this little guy, age = input("Please tell me your age?: ") age_test = eval(age) if age_test < 1: print("You can't be negative!") if age_test > 100: print("You can't be over…
DaltonM
  • 39
  • 4
-3
votes
3 answers

I know this is simple but still these if statements are annoying. when I run it always says length is not defined

Here is my code: #Starting Point import time print("This calculator will convert measurements into a unit of choice") time.sleep(2) print("Here are the choice:") time.sleep(0.5) print("") print(" Centimetres, Metres,…
-3
votes
1 answer

When my conditional is false in when it turns true why wont the loop stop

Here is my code in python 3.4 it just keeps running the loop until the system exit when the player dies this is part of an rpg game i have been making for fun Not entire code please note if you would like to see entire code please ask only combat…
-3
votes
1 answer

Converting Values to Switch Statement Cases

For a programming class, I have to convert a range of values to a switch statement without using if/else ifs. Here are the values that I need to convert to cases: 0 to 149 ............. $10.00 150 to 299 .........$15.00 300 to 449…
Alyssa
  • 23
  • 1
  • 7
-3
votes
1 answer

How to define a function with a statement block in C or C++?

So as the title suggests I'm interested in defining a function that has a statement block. What this means is best explained via example: for(int i=0;i<10;i++){ } How could I define a function that has a block like…
-3
votes
1 answer

How 'heavy' are the following statements?

So lately I've been trying to figure out how 'heavy' some statements are. For example is it a good thing to check for every possible exception with if statements or will that slow down the programm considerably? So I bassically want to know how…
Roan
  • 1,150
  • 2
  • 20
  • 29
-3
votes
1 answer

Consecutive if statement flow

if (srcbloc == NULL) { fprintf(stderr, "warning!: memrip source is null!\n"); exit(1); } if (destbloc == NULL) { destbloc = malloc(len); } if (srcbloc == destbloc) { fprintf(stderr, "warning!: srcbloc = destbloc\n"); …
skrillac
  • 11
  • 1
  • 3
-4
votes
3 answers

How do I fix this While statement in my Pythagorean theorem code?

So I am trying to write a simple code that will do the Pythagorean theorem for me after I input A, B and C but the code is skipping my While statements, and I have tried rewriting them as if statements to see if that works and again it will skip it,…
-4
votes
3 answers

boolean in Java program

1: I got confused by how both of these variables: boolean firstNumberEntered=false; boolean secondNumberEntered=false; control the conditions inside and outside the loop? 2: what will the values before and after it exits While loop? 3: can…
1 2 3
30
31