A
A
AlexaAioGram2021-07-12 16:55:06
Python
AlexaAioGram, 2021-07-12 16:55:06

How to loop until a condition is met?

questions are shown in the code with a hash mark #

@dp.message_handler(state=oprosnik.Q7, content_types=ContentTypes.TEXT)
async def vopros6(message: Message, state: FSMContext):
    kted = message.text
    if message.text.lower() not in kted:
        return
    gg = message.from_user.id
    await bot.send_message(chat_id=ADMIN, text=f'Опыт в сфере игр: {italic(kted)} ({gg}\n)',
                           parse_mode=ParseMode.MARKDOWN, reply_markup=item_all)


    await message.answer('✨Вы заполнили анкету, ждите ответа от модерации✨')
    while 1:  #МНЕ НАДО ЧТО ПОКА ЮЗЕР НЕ НАЖАЛ НА КНПОКУ, КОД ДАЛЬШЕ НЕ СДВИГАЛСЯ

        if 'Принять заявку✅' in message.text:
            await message.bot.send_message(chat_id=gg, text='Вы приняты ✅', reply_markup=all_accept)
            await message.delete_reply_markup()

        elif 'Отклонить заявку' in message.text:
            await message.answer('Вам отклонили заявку')
            await message.delete_reply_markup()
            await state.finish()
            break
# The cycle ends

Please help me with the code, I just don’t understand cycles

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Emil Timerbaev, 2021-07-12
@MrDlop

Create another function and make a transition to it.

S
Sergey Pankov, 2021-07-12
@trapwalker

You don't need any loop here. Just consider that in response to each message or user click, you re-enter this function. Separate the pieces of the algorithm by a condition on the content of the input text. Do actions only in branches.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question