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 6919145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:57:09+00:00 2026-05-27T09:57:09+00:00

how can i stop my loop if prod_Available < 0 (negative value) and returns

  • 0

how can i stop my loop if prod_Available < 0 (negative value) and returns status = 0 else it returns status = 1?. Is it possible that when my loop encounters prod_Available < 0 it will stop looping and returns status = 0.?

here is my code :

   def get_hotel_sum_quantity(self, product_id, checkin_date, checkout_date, quantity):
        check_in = datetime.datetime.strptime(checkin_date, '%Y-%m-%d')
        check_in = check_in.date()
        start_date = check_in.day

        check_out = datetime.datetime.strptime(checkout_date, '%Y-%m-%d')
        check_out = check_out.date()
        end_date = check_out.day

        prod = Product.objects.get(id=product_id)
        prod_Available = 0
        array = []
        for x in range(start_date,end_date + 1):
            x = x - start_date
            delta = datetime.timedelta(days=x)
            all_date = check_in + delta
            sumOfQuantity = HotelCheck.objects.filter(date_booked=all_date, product=prod).aggregate(Sum('quantity'))['quantity__sum']
            if sumOfQuantity == None:
                sumOfQuantity = 0
            prod_Available = prod.quantity - sumOfQuantity
            prod_Available = float(prod_Available) - float(quantity)

            if prod_Available < 0:
                status = 0
            else:
                status = 1
            data = {'available': prod_Available, 'status': status, 'sumquantity': sumOfQuantity, 'quanity': quantity}
            array.append(data)           
        return array

i have already returned all the value but it wont stop looping when prod_Available < 0
here is what i have done:

>>> from booking.models import *
>>> Hotel.objects.get_hotel_sum_quantity(3, '2011-12-21', '2011-12-24', 1)
[{'available': 1.0, 'status': 1, 'sumquantity': 8, 'quanity': 1}, {'available': 1.0, 'status': 1, 'sumquantity': 8, 'quanity': 1}, {'available': 1.0, 'status': 1, 'sumquantity': 8, 'quanity': 1}, {'available': 9.0, 'status': 1, 'sumquantity': 0, 'quanity': 1}]
>>> Hotel.objects.get_hotel_sum_quantity(3, '2011-12-21', '2011-12-24', 2)
[{'available': 0.0, 'status': 1, 'sumquantity': 8, 'quanity': 2}, {'available': 0.0, 'status': 1, 'sumquantity': 8, 'quanity': 2}, {'available': 0.0, 'status': 1, 'sumquantity': 8, 'quanity': 2}, {'available': 8.0, 'status': 1, 'sumquantity': 0, 'quanity': 2}]
>>> Hotel.objects.get_hotel_sum_quantity(3, '2011-12-21', '2011-12-24', 3)
[{'available': -1.0, 'status': 0, 'sumquantity': 8, 'quanity': 3}, {'available': -1.0, 'status': 0, 'sumquantity': 8, 'quanity': 3}, {'available': -1.0, 'status': 0, 'sumquantity': 8, 'quanity': 3}, {'available': 7.0, 'status': 1, 'sumquantity': 0, 'quanity': 3}]
>>> 

can anyone can give me an idea about my situation?

thanks in advance

  • 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-05-27T09:57:09+00:00Added an answer on May 27, 2026 at 9:57 am

    Mayb you could use the break statement of python to stop your loop :

    if prod_Available < 0:
        status = 0
    else:
        status=1
    
    data = {'available': prod_Available, 'status': status, 'sumquantity': sumOfQuantity, 'quanity': quantity}
    array.append(data)         
    if status == 0:
       break
    

    then, when prod_available will be under 0, it will stop the loop and your method will continue execution (and return array in your case)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that can stop and start services using SilverLight
I've got a virtual machine running on a server that I can't stop or
How can I stop the loop until a key is pushed? for (i=1;i<10;i++){ $('input').eq(i).css('border','1px
I have a program that will analyzes source code. It can recursively go through
Possible Duplicate: How would I stop this foreach loop after 3 iterations? I have
Can anybody tell me why the loop did not stop after the 5 entry?
I have looked and tried but don't see where I can stop some being
How can i stop the host machine entering standby mode while my application is
How can I stop a background thread on keyboard flip in android?
How can I stop a build, and notify the user if a file does

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.