Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:33:49+00:00 2026-06-10T02:33:49+00:00

I have the following (simplified) conditions that need to be validated for a form

  • 0

I have the following (simplified) conditions that need to be validated for a form I am writing:

a > b

a > c

a > d

b > c

b > d

c > d

Graphically, this can be seen as:

enter image description here

The user has freedom to enter values for a, b, c, and d, which is why they need to be validated to make sure they obey those rules. The problem I am having is writing something that clearly and efficiently evaluates each statement. Of course, the most obvious way would be to evaluate each statement separately as an if-statement. Unfortunately, this takes up a lot of lines of code, and I’d rather avoid cluttering up the method with a bunch of if-blocks that do almost the same thing. I did come up with the following nested for-loop solution, using arrays. I built an array of the values, and looped over it twice (demonstrated in Python-like pseudo-code):

A = [a, b, c, d]
for i in range(3):
    for j in range(i, 4):
        if i > j and A[i] >= A[j]:
            print("A[i] must be less than A[j]")
        else if i < j and A[i] <= A[j]:
            print("A[j] must be greater than A[i]")

The problem I have with this solution is it is hard to read and understand – the solution just isn’t clear.

I have this nagging feeling that there is a better, clearer answer out there, but I can’t think of it for the life of me. This isn’t homework or anything – I am actually working on a project and this problem (or subtle variations of it) arose more than once, so I would like to make a reusable solution that is clear and efficient. Any input would be appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:33:50+00:00Added an answer on June 10, 2026 at 2:33 am
    if a > b > c > d:
        do ok
    else:
        for x in range(3):
            if A[i] <= A[i+1]:
                 print A[i], ' not greater than', A[i+1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an algorithm I'm writing, I can have the following (simplified of course) int
I have the following - simplified - models: class User(models.Model): following = models.ManyToManyField(self, through='Following',
I have the following (simplified to make this easy to read) first class: Class
I have the following entities: User Company Organization Users need to be able to
I have the following (simplified) XML that I get in a system environment: <?xml
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have the following (simplified) public enum Level { Bronze, Silver, Gold } public
I have the following simplified XML: <?xml version="1.0" encoding="UTF-8" ?> <MATMAS05> <IDOC BEGIN="1"> <E1MARAM
I have the following (simplified) database tables: Products - ProductID, int, PK - Name,
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.