Jump to content
Killersites Forums

What are some examples of using a for-loop, while-loop, and if-else statements?


SubhanUllah
 Share

Recommended Posts

 

I make this answer using Python programming language, this is very similar to pseudocode:

limit_patience = 10 
you_understand = False 
while not you_understand: 
    for intents in range(limit_patience, 0, -1):  # loop while I have patience 
            print("I'll teach you about if-else, for and while loops")  # I'll explain 
            your_answer = input("If you understood, write 'Yes'")  # Do you know now? 
            if your_answer == "Yes":  # You answer me 
                print("Congratulations: you are a genius") 
                you_understand = True 
                break  # exit inner loop 
            else:  # if not write 'Yes' 
                print(F"Ok, I'll keep teaching you by {intents} time")  # say this sentence 
            print("I teach again, AGAIN!")  # this is inside the main loop 
            # the loop to repeat to this point 
        else:  # you have reached the limit of my patience 
            # the else clause of the for loop exits here when the loop reaches its normal end,        
            # not when it exits via a break clause 
            print("My God: you're a donkey") 
            break  # breaks out of the main loop 
else: 
    # the else clause of the while loop exits here when the loop ends normally, 
    # that is when the while condition is not met 
    print("You already know if-else, for and while loops") 
# I hope I'm not wrong 

 

Edited by SubhanUllah
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...