Can I use an assignment in a switch case?
Baby programming student here. An assignment asks for me to use a few loops to count from 1 - 100, and in one of the loops I have to include a switch statement that prints some things depending on the conditions. Here is what the assignment is: "Create a basic program that accomplishes the following requirements:
- Uses a for statement to count from 1 to 100.
- Uses a while statement to count from 1 to 100.
- Use a do while statement to count from 1 to 100.
- Using a switch statement in one of the loops , print to the screen if a number is: Less than or equal to 10, Greater than or equal to 11 but less than 20, Greater than 21."
I can complete the looping statements just fine, and I can write a switch statement, but putting a switch statement inside of a loop that is already counting seems impossible. From my understanding, a case in a switch statement must be an integral value (like '1') and cannot be an assignment (like 'counter <= 10'). I have done so much research and found no help or clarity from my professor or any youtube tutorial. I am at wits end here; is there something I'm just not understanding about switch statements? I feel so lost.
from Recent Questions - Stack Overflow https://ift.tt/3ab0RIt
https://ift.tt/eA8V8J
Comments
Post a Comment