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

  • Thread starter Thread starter chetzread
  • Start date Start date
  • Tags Tags
    Loop
Click For Summary
SUMMARY

The discussion clarifies the use of the '==' operator in while loops within C programming, specifically in the context of checking user input for both uppercase 'Y' and lowercase 'y'. The code is not incorrect; it effectively utilizes character constants to evaluate user responses. Participants highlighted the importance of understanding different constant types in C, including character constants, string constants, integer constants, and floating-point constants, to grasp control structures fully.

PREREQUISITES
  • Understanding of C programming syntax
  • Familiarity with control structures in C
  • Knowledge of character constants in C
  • Basic understanding of data types in C
NEXT STEPS
  • Study C programming control structures in depth
  • Learn about character constants and their usage in C
  • Explore the differences between character constants and string constants in C
  • Investigate the implications of using '==' in conditional statements
USEFUL FOR

Students learning C programming, educators teaching control structures, and developers seeking to understand user input validation in C.

chetzread
Messages
798
Reaction score
1

Homework Statement


for the 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: 407
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.
 

Similar threads

Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K