• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

if statement logic

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If loop doubt.
e.g, if I have variables a,b,c and d and based on the variables, I need to perform certain actions.


// There are many other if statements related to other variables before this
if (a || b || c || d) {
if (a){ DoSomething related to A}
if (b){ DoSomething related to B}
if (c){ DoSomething related to C}
if (d){ DoSomething related to D}
}
// There are many other if statements related to other variables after this

Is the first if statement, to check if the variables are present, a good idea, or not needed at all, or based on case to case?
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UseCodeTags <- (this is a link) for codes so that it will be easy to read.
In general I do not think 1st if-condition id needed.
Others can be put in if-else if-else conditions or switch-case.
 
Marshal
Posts: 76412
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tapas Chand wrote:UseCodeTags

Agree. And also please indent youir code properly; we have some suggestions here. Simply adding code tags would probably make that code even harder to read without indentation and suqashed together into 4 lines.

. . .if-else if-else conditions or switch-case.

Yuo mean like this?A switch works really nicely but it is restricted in the range of arguments it can take, so cannot be used in all circumstances.
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, I meant that only.
My bad, did not explain clearly enough.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic