logo
down
shadow

Looping back after condition is false


Looping back after condition is false

By : Atom97
Date : November 17 2020, 01:00 AM
wish helps you Because that's what your while loop says: "loop while the input is between 1 and 4" , which becomes false when the user enters invalid input.
Given you only want to exit when the input equals four, nothing else:
code :
while (userSelection != 4)


Share : facebook icon twitter icon
Do/While Loop looping when condition set to false

Do/While Loop looping when condition set to false


By : Spark
Date : March 29 2020, 07:55 AM
I wish this help you If input.hasNextInt() ever returns false, then your loop is going to run forever because you do nothing to advance the input and it will return false on every iteration. My guess (without more details about your program's behavior) is that this is what's going on.
You need to somehow consume the current input to clear the error condition. The logic for doing this depends on what you're expecting as input.
Function not looping back when an certain condition is met

Function not looping back when an certain condition is met


By : Indumathi
Date : March 29 2020, 07:55 AM
this one helps. You don’t need the query statements at the end. Include the calls to your methods in the methods or create a new one for the purpose of returning to the main menu. I would also suggest using float() instead of int() when dealing with possible decimals, but I did not change this.
code :
class Pytha(object):
    def __init__(self):
        import time, math
        self.math = math
        self.time = time
        print("Welcome to the pythagorean theorem calculator!\n")
        self.time.sleep(1)
        self.mainmenu()

    #custom function for solving for c
    def cal(self):
        try:
            a = int(input('\nPlease enter the "A" value: '))
            b = int(input('Please enter the "B" value: '))
            print("Calculating...")
            self.time.sleep(1)
            print('The "C" value is ')
            c = self.math.sqrt(a*a + b*b)
            print(c)
        except ValueError:
            print("\nError: Please enter a number\n")
            self.cal()
        self.rerun()

    #function for solving for a or b, given c
    def cal2(self):
        try:
            var = int(input('\nPlease input either the "A" or "B" value: '))
            c = int(input('Please input the "C" value: '))
            var2 = float(c)**2 - float(var)**2
            ans = self.math.sqrt(var2)
            print('The "A"/"B" value is {0}'.format(ans))
        except ValueError:
            print("\nError: Please enter a number\n")
            self.cal2()
        self.rerun()

    def mainmenu(self):
        query1 = str(input('Welcome to the main menu! Solve for "C" or "A"/"B" or quit program? (opt1/opt2/q)\n'))
        if query1.lower() == "opt1":
            self.cal()
        elif query1.lower() == "opt2":
            self.cal2()
        elif query1.lower() == 'q':
            quit()
        else:
            print("Error: Please type 'opt1' or 'opt2' or 'q'\n")
            self.mainmenu()

    def rerun(self):
        query1 = str(input('\nAnother Calculation? Solve for "C" or "A"/"B" or quit program? (opt1/opt2/q)\n'))
        if query1.lower() == "opt1":
            self.cal()
        elif query1.lower() == "opt2":
            self.cal2()
        elif query1.lower() == 'q':
            quit()
        else:
            print("Error: Please type 'opt1' or 'opt2' or 'q'\n")
            self.rerun()

app = Pytha()           
class Pythag(object):
    #custom function for solving for c
    def solve_C(a, b):
            from math import sqrt
            a = int(a)
            b = int(b)
            c = sqrt(a*a + b*b)
            return (c)

    #function for solving for a or b, given c
    def solveAB(var, c):
            from math import sqrt
            var = int(var)
            c = int(c)
            var2 = float(c)**2 - float(var)**2
            ans = sqrt(var2)
            return(ans)
from pythag import Pythag
Pythag.solve_C(4,5)
How to continue looping while the condition is false

How to continue looping while the condition is false


By : ibrahim Hashmi
Date : March 29 2020, 07:55 AM
wish helps you You need to ask user to enter number in a loop. The condition of the loop will be the condition of your if. Then after exiting the loop (which means user enter a correct number), enter your for loop.
This will look like that :
code :
int actorsNumber = -1; //force a wrong value at the beginning
while(actorsNumber < 1 || actorsNumber > 5) {
    //Ask user to enter a number between 1 and 5
    //store this number in actorsNumber
}
//As we exited the while-loop, actorsNumber is between 1 and 5
//Put your for-loop here
Using IF condition inside a while loop in C#. False value still looping

Using IF condition inside a while loop in C#. False value still looping


By : Siddharth Mishra
Date : March 29 2020, 07:55 AM
should help you out You should use String.Equals(user1 ,txtUsername.Text.ToString ()) and String.Equals(pass1 ,txtPassword.Text.ToString ()) instead of user1 == txtUsername.Text and pass1 == txtPassword.Textin your if. To have correct string comparison
You should move else part outside of your loop. If username and password are correct then add break; as your last statement in if condition.
Why does my FirstFactorial program keep looping back to while condition even after the condition is not met

Why does my FirstFactorial program keep looping back to while condition even after the condition is not met


By : Sahm Zheii
Date : March 29 2020, 07:55 AM
like below fixes the issue Here's the code snippet, this when run with number 4 outputs 2424242448484848288288288288576576576576. Not sure as to why would the execution would jump back to while loop after exiting the function code. Any help will be appreciated. Thank you in advance. , Within the function
code :
void
FirstFactorial(int num)
{
  // code goes here
  while(num > 0)
    {
      result = result * num;
      num--;
      FirstFactorial(num);
    }
  printf("%d", result);
}
#include <stdio.h>

unsigned long long int factorial( unsigned long long int n )
{
    return n < 2 ? 1 : n * factorial( n - 1 );
}

int main(void) 
{
    printf( "%llu! = %llu\n", 4llu, factorial( 4 ) );
    printf( "%llu! = %llu\n", 20llu, factorial( 20 ) );

    return 0;
}
4! = 24
20! = 2432902008176640000
Related Posts Related Posts :
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org