Skip to main content

All Questions

Tagged with
0 votes
1 answer
63 views

Immediate break after input using switch or if

I am learning C right now and im at the very beginning. Here's my code: #include <stdio.h> int main (){ char operator; double num1; double num2; double result; printf("\n Enter an ...
Bunyamin Erkaya's user avatar
1 vote
1 answer
44 views

Switch executes default even with break in every case

So i'm trying to break out of the switch and while statements using the break in every case, yet even using the break statement my program keeps executing the default after the specific case code is ...
Heaper's user avatar
  • 15
0 votes
2 answers
84 views

Why does break work in switch blocks but not if-else blocks in C? [closed]

Just beginning with C and noticed this detail. Not a pressing question, just curious. I tried searching for the answer but couldn't seem to find an explanation. (not sure what else to say, this ...
jktannerman's user avatar
3 votes
2 answers
1k views

What is the benefit of 'break' in 'switch' statement (Dart Language)?

When I write this code void main() { var age = 18; switch(age){ case 18: print("Age is 18"); case 22: print("Age is 22"); default: print("...
Omar Azzam's user avatar
0 votes
2 answers
39 views

Why next statements in the switch block after matching a case are executed if break keyword is not used? [duplicate]

class Switch{ public static void main(String[] args){ int x = 2; switch(x){ case 1 : System.out.println("1"); case 2 : System.out.println("2&...
Rakesh Reddy's user avatar
1 vote
2 answers
83 views

Why does a non-default last-case execute in JavaScript switch?

I have (ab)used a switch statement like this: const foo = figureOutWhatFooIs() console.log(foo) // 'bar' switch (foo) { case 'bar': console.log('foo = bar') case 'baz': console.log('foo = ...
Aaron Parisi's user avatar
0 votes
3 answers
257 views

Conditionally return or break a switch case

I am refactoring a switch statement in which I am performing am if conditional within one of the cases where the if will break the switch case and the else will return. Is it possible to perform this ...
physicsboy's user avatar
  • 6,074
1 vote
0 answers
169 views

Java is not accepting "break" in switch statement

I trying to insert "break" code in switch statement in java for stop looping output. I insert the break in switch statement, but the java is giving the "break is unusual statement" ...
Harish M's user avatar
0 votes
2 answers
970 views

switch in switch, does the outer case break if inner case break

In languages that have switch, usually a break; statement is needed. What if a switch within a switch statement? Is it necessary to put a break; statement in the outer switch when the inner switch has ...
Simeng Fu's user avatar
0 votes
1 answer
48 views

If statements inside Switch inside While loop leads to unexpected output

There are surely ways to write the following code in a more practical way.But I really want to understand why it is printing the line "Write action (buy, fill, take, remaining, exit):" two ...
DinoChunk's user avatar
0 votes
1 answer
43 views

Why is my code executing on every switch case instead of breaking?

Code is meant to take two arguments that I type in when I call playRound in the console. When I put in 'rock' as both playerSelection and computerSelection it executes all code under playerSelection ...
Devon Kahika-Campbell's user avatar
0 votes
0 answers
31 views

I am trying to 'break' the loop, but the function just keep looping [duplicate]

I separated my program mainly into two parts. -One is the function which I used 'if' in a 'while' loop, one is the main body which is still a 'while' loop but the inside is a switch statement When I ...
Ray Chan's user avatar
0 votes
2 answers
244 views

While loop is not stopping/ break command doesn't work JAVA

I'm trying to make a Queue where you can have different commands for different functions and I used a while loop in order for it to be reusable. But the break; command in the switch case is not ...
Ocean Man's user avatar
0 votes
1 answer
269 views

Switch case statement doesn't loop

All its doing is running functions but for some reason it doesn't break after I press r, it just runs the function then ends the program. int main() { char key = 0; PPMImage *img = NULL; ...
Daniel Bland's user avatar
-1 votes
2 answers
83 views

Code executes all cases even with break statement

This a simple program to rotate bits, the switch case used to define if the user wants a left rotating or right rotating after getting the most significant bit or the least significant bit depending ...
UnderScore's user avatar

15 30 50 per page
1
2 3 4 5
9