Understanding the Use of '==' in While Loops: Explanation and Example

  • Thread starter Thread starter chetzread
  • Start date Start date
  • Tags Tags
    Loop
AI Thread Summary
The discussion clarifies the use of '==' in while loops, specifically in checking user input for 'Y' or 'y'. It emphasizes that character constants, like 'y', are used to compare against user input, ensuring both uppercase and lowercase are recognized. The conversation also touches on the types of constants in C, including character, string, integer, and floating-point constants. This understanding is crucial for correctly implementing control structures in programming. Overall, the thread provides insight into character constant usage in conditional statements.
chetzread
Messages
798
Reaction score
1

Homework Statement


for teh circled part , why there's again =='y' ? i didnt see the variable 'y' anywhere other than the circled part ...What does it mean ?

Homework Equations

The Attempt at a Solution


Is the code wrong ?
 

Attachments

  • 1.PNG
    1.PNG
    11.9 KB · Views: 387
Physics news on Phys.org
Characters in quotes are character constants. The statement in question is checking whether the user has input a 'Y' or a 'y' (so that both upper and lower case are checked).
 
@chetzread, before you learned about loops and other control structures, there was probably some mention about the various types of constants that can be used in C. At least most of the books I've seen present such material in that order.

Character constants, such as 'y' or 'B' or '\t'
String constants, such as "cat"
integer constants, such as 23, 023, and 0x23 (all with different values)
floating point constants, such as 2.7 (a double) and 3.09F (a float)
This is not meant to be an exhaustive list.
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
10
Views
3K
Replies
3
Views
7K
Replies
8
Views
3K
Replies
4
Views
2K
Replies
3
Views
1K
Replies
2
Views
1K
Back
Top