while-loop

NoSuchElementException Issue

こ雲淡風輕ζ 提交于 2019-12-13 15:16:12
问题 What I am trying to do is to create a while loop where a program menu is run from until the user inputs a valid response. However the scanner instance I have created does not want to play ball and keeps throwing NoSuchElementExceptions no matter what I have tried. import java.util.Scanner; public class Menu { Menu() { isValid = false; uInput = 0; } public int mMain() { Scanner in2; do { in2 = new Scanner(System.in); //For user input System.out.println("Please choose from the following options

How to use raw_input() with while-loop

别说谁变了你拦得住时间么 提交于 2019-12-13 13:31:58
问题 Just trying to write a program that will take the users input and add it to the list 'numbers': print "Going to test my knowledge here" print "Enter a number between 1 and 20:" i = raw_input('>> ') numbers = [] while 1 <= i <= 20 : print "Ok adding %d to numbers set: " % i numbers.append(i) print "Okay the numbers set is now: " , numbers However when I execute the program it only runs to raw_input() Going to test my knowledge here Enter a number between 1 and 20: >>> 4 Is there some

C# While Loop vs For Loop?

十年热恋 提交于 2019-12-13 13:05:31
问题 In C# a question has been bugging me for a while and its what is that actual major difference between a While and For Loop. Is it just purely readability ie; everything you can essentially do in a for loop can be done in a while loop , just in different places. So take these examples: int num = 3; while (num < 10) { Console.WriteLine(num); num++; } vs for (int x = 3; x < 10; x++) { Console.WriteLine(x); } Both code loops produce the same outcome and is the only difference between the two that

C++ Try Catch inside loop

拟墨画扇 提交于 2019-12-13 12:30:08
问题 I have this C++ program with the following general structure 1st while (condition A == true) //some code for 1st loop 2nd while (condition B == true) //some code for 2nd loop try //some code for try catch //condition B == false (supposed to leave 2nd loop and go back to first loop) I want it to get out of 2nd loop when there's an exception and go back to 1st loop until condition B is tue again. As described above it doesn't work as I expect. What seems to be happening is that code gets stuck

F# break from while loop

流过昼夜 提交于 2019-12-13 11:52:43
问题 There is any way to do it like C/C# ? For example (C# style) for( int i=0; i<100; i++) { if(i==66) break; } 回答1: The short answer is no. You would generally use some higher-order function to express the same functionality. There is a number of functions that let you do this, corresponding to different patterns (so if you describe what exactly you need, someone might give you a better answer). For example, tryFind function returns the first value from a sequence for which a given predicate

How to prompt the user to enter a integer within a certain amount of numbers

时光怂恿深爱的人放手 提交于 2019-12-13 11:28:45
问题 I was trying to figure out what statement to use to get the user to enter a number between 1 and 10. here is what i have so far. int a; printf("Enter a number between 1 and 10: \n); scanf("%d", &a); 回答1: int input; while (true){ scanf("%d",&input); if (input>=1 && input<=10){ // process with your input then use break to end the while loop } else{ printf("Wrong input! try Again."); continue; } } 回答2: Number beteween 1 to 10 right? so first stage you must validate if input is integer or not

How to go back to menu using case in switch case in C

孤者浪人 提交于 2019-12-13 11:25:27
问题 How to go back to menu using case in switch case without using GOTO command. So this is the sample: while(1){ printf("1: Basic Math\n2. Intermediate Math\n3. Advance Math"); printf("Enter your choice: "); int choice; scanf("%d", &choice); switch(choice) int theChoices; case 1: printf("1. Add\n 2. Subtract\n3. Go back to menu"); scanf("%d", &theChoices); switch (theChoices) { case 1: //calculation ... case 2: //calculation ... case 3: // Go Back to menu which is Basic math, Intermediate Math,

How to create a loop for multiple players turn?

喜夏-厌秋 提交于 2019-12-13 11:10:51
问题 Im trying to get this loop to work, but it just refuses to work. Any help would be very much appreciated. while player1_score < 100 and player2_score < 100 and player3_score < 100 and player4_score < 100: while player_turn != playerholder: dice_rolling() scoring() score_awarding() player_turn = player_turn + 1 if player_turn == playerholder: player_turn == 1 What im trying to do is get the number of players present (playerholder) and then keep player turn within the bounds of it i.e repeating

How to get <th> to loop through fetch results without being in a table loop [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-13 11:04:02
问题 This question already has an answer here : Issues getting table headers to position correctly (1 answer) Closed 4 years ago . I am designing a table and I am having difficulties with a <th> . The <th> is usernames from my database, so I need to fetch them, so that they can even display on the page. I am currently fetching everything from my database table through a fetch while loop. Whenever, I put the <th> in my loop it ruins the structure of my table. I am trying to create a table that

Can't set the correct value in this while loop

牧云@^-^@ 提交于 2019-12-13 10:48:04
问题 I have translated this code to VB.NET which is a function to check if a image is grayscale. private static unsafe bool IsGrayScale(Image image) { using (var bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb)) { using (var g = Graphics.FromImage(bmp)) { g.DrawImage(image, 0, 0); } var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat); var pt = (int*)data.Scan0; var res = true; for (var i = 0; i < data.Height * data