logo
down
shadow

Repeating for loop in menu


Repeating for loop in menu

Content Index :

Repeating for loop in menu
Tag : java , By : wraith
Date : November 24 2020, 03:41 PM

wish help you to fix your issue Both your while loops continue looping as long as choice != 8. And since you never modify the choice inside the loop, it will just continue looping (unless 8 was input by the user).
Also note that the break; you added are breaks for the switch-case, not to stop the do-while-loop. To have a break within the switch-case stop the entire do-while-loop, you should use a label to give the loop a name, and break that one. In addition, you should ask the user to give a new input if it didn't came into one of the switch-cases, otherwise it will still loop forever. So something like this:
choice = kboard.nextInt();
myLoop: do {
  switch(choice) {
    case 1:
      f1.displayFloor();
      break myLoop;
    case 2:
      f2.displayFloor();
      break myLoop;
    case 3:
      f3.displayFloor(); 
      break myLoop;
    case 4:
      f4.displayFloor(); 
      break myLoop;
    default: // Not one of the above
      System.out.println(choice + " is an unknown choice. Please choose again.");
      choice = kboard.nextInt(); // Ask the user for a new input
      break; // <- This break only breaks the switch, not the loop
  }
} while(choice !=8);
choice = kboard.nextInt();
do {
  switch(choice) {
    case 1:
      f1.displayFloor();
      break;
    case 2:
      f2.displayFloor();
      break;
    case 3:
      f3.displayFloor(); 
      break;
    case 4:
      f4.displayFloor(); 
      break;
    default: // Not one of the above
      System.out.println(choice + " is an unknown choice. Please choose again.");
  }
  choice = kboard.nextInt(); // Ask the user for a new input for the next iteration
} while(choice !=8);

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Code repeating although not in a repeating loop python


Tag : file , By : user171752
Date : March 29 2020, 07:55 AM
may help you . You wrote the loop to go through each line of the file; unless you stop the loop, it will continue to do so.
I think you want to wait until after the loops is done (and the name was not found) before adding it to the file.

Php array. Loop. If condition true, set variable. Again loop. Need to repeat. But without repeating the same code


Tag : php , By : Mahesh
Date : March 29 2020, 07:55 AM
I hope this helps . Here is longer example https://eval.in/392036 , It looks like you have a recursive pattern:
function loopMyArray(&$array, &$parent, $i)
{
    // That's your stop condition of the recursive pattern
    // I think it's what you want.
    if (count($array) == $i)
    {
        return;
    }
    // The foreach loop call the "loopMyArray" at each iteration
    foreach ($array as $k_arr => $v_arr)
    {
        if( $v_arr['ParentId'] == $parent[$i])
        {
            echo $v_arr['Value']. "\n";
            $parent[$i+1] = $v_arr['Id'];
            loopMyArray($array, $parent, $i+1);
        }
    }
}

$array = [...]
$parent = [0]
loopMyArray($array, $parent, 0);

Java Menu Using Do while loop keeps repeating


Tag : java , By : user103892
Date : March 29 2020, 07:55 AM
wish of those help Your statement count = count++ looks wrong. Use just count++ or count = count + 1.
Using count = count++ creates byte code somewhat like this:
 temp = count
 count = count + 1
 count = temp
count = count + 1
count = count

Adding menu items to a Tkinter menu in a loop results in the last menu item being returned


Tag : python , By : greggerz
Date : March 29 2020, 07:55 AM
Does that help We found a way to make this work. Change
stopworkermenu.add_command(label=m, command=lambda: popup(m)

do while 1-4 menu loop continually repeating for non numerical input


Tag : c , By : moss
Date : March 29 2020, 07:55 AM
Hope that helps I'm having trouble with this do while menu loop as part of a bigger programming question, it keeps repeating for any non numerical input. How can I prevent this ? Any help would be great thanks! , The reason it keeps repeating is because
scanf("%d", &option)
if ((scanf("%d", &option) != 1))
{
    printf(">Invalid option! ");
}
if ((scanf("%d", &option) != 1))
{
    printf(">Invalid option! ");
    break;
}
void clean_stdin(void)
{
    int c;
    while((c = getchar()) != '\n' && c != EOF);
}
if ((scanf("%d", &option) != 1))
{
    printf(">Invalid option! ");
    clean_stdin();
    continue; // to skip the rest of the loop
              // and start the loop again
}
Related Posts Related QUESTIONS :
  • Fully decompile java6 web application
  • Passing keycloak configuration parameters in the code rather than reading from application.properties
  • setDataSource() IO exception
  • Unexpected Output while retrieving Data from mongodb and displaying in a csv file?
  • Algorithm for searching a value in two arrays
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • Assert progress of ProgressBar in Espresso test
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • Multi-tenant migration to work with quarkus
  • Ignite persisting a Set: Cannot find metadata for object with compact footer
  • Maven cannot resolve Jacob dependency using eclipse
  • testcontainers oracle database container starts before database user is created
  • Launching two spring boot apps in integration test
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com