while-loop

PHP - How to combine arrays into one array in while loop?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:54:35
问题 I have this code which gives me post_permalink in a while loop. <?php $value[] = array(); while ($the_query->have_posts()) : $the_query->the_post() $value[] =array( 'post_permalink' => get_permalink() ); endwhile; ?> Now the thing is that I'm getting the links as Array ( [0] => Array ( [post_permalink] => link ) [1] => Array ( [post_permalink] => link ) [2] => Array ( [post_permalink] => link ) [3] => Array ( [post_permalink] => link ) ) The way I want it to be: Array ( [post_permalink] =>

While Loop with hasNextInt() actually reading?

五迷三道 提交于 2019-12-24 00:48:29
问题 Hello my problem is with this program. int integer = 0; int evenInts = 0; Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); integer = in.nextInt(); while(in.hasNextInt()){ System.out.print("Enter an integer: "); integer = in.nextInt(); } It should read in an int after "Enter an integer: " is asked. After that as long as integers are put in the input this procedure gets repeated. Actually it prints something like this : Enter an integer: 10 10 // so basically the

Accepting user input in a while loop

六月ゝ 毕业季﹏ 提交于 2019-12-24 00:32:10
问题 I'm trying to create a simple temperature conversion program that allows the user to convert temperatures as many times as they want until they decide to end the program by entering the letter 'e'. Everything else in the code works except the part where the user enters the letter 'e'. If I take the last else statement out, the program just starts at the beginning of the loop again. If I leave the else statement in, when the user enters the letter 'e', the else statement thinks that it is

do while syntax for java

别说谁变了你拦得住时间么 提交于 2019-12-24 00:25:11
问题 Ages since I have written a do while. Whats wrong with this do while int i = 0; do { System.out.println(i); } while(++i == 500); I only goes once through the loop, and IMO it should iterate 500 times. 回答1: You probably meant while (++i < 500); instead of while (++i == 500); 回答2: It is a do-while loop of Java, not the repeat-until loop of Pascal. Its expression specifies the continuation condition , not the exit condition . do { System.out.println(i); } while(++i != 500); 回答3: It will only

php - create assciative array while loop

被刻印的时光 ゝ 提交于 2019-12-24 00:06:33
问题 I am trying to create 2 new arrays out of one existing array ($array), using the following "foreach" loop. However I am not sure it is correct: $emails = array(); $numbers = array(); while($array){ $entry = $array['entry1']; $number = number($entry); if(isset($number) && (strlen($number) > 9)){ $numbers[] = array('entry1' => $entry, 'number' => $number); } else{ $email = email($entry); $emails[] = array('entry1' => $entry, 'email' => $email); } } should the internal arrays have [] ? do I even

Python: How to repeat the last input prompt before wrong input?

北慕城南 提交于 2019-12-23 23:18:28
问题 I have an for statement which prompts the user to input 5. numbers. Like this: "Input 1. number: input 2. number: .. .. .." I want to repeat the last prompt the user gets before he makes a wrong input (number too big). But my program skips the wrong one: like this "Input 1. number: 5 Accepted input 2. number: 999 Wrong! Retry (here I use *continue* for the loop) input 3.number: ---" What should I do to re-ask the second question? 回答1: By using continue you are probably continuing ahead to the

Adding numbers from 1 to N in C#

五迷三道 提交于 2019-12-23 22:25:42
问题 I'm writing code in C# and trying to add all of the numbers between the number 1 and N, N being the number that is inputted in a textbox. I'm doing this, at least trying to do this, by putting it into a while loop. I have added all the numbers between 2 textboxes before but for some reason I'm driving myself crazy and can't figure this out. I'm a beginning programmer so please be gentle. Any help would be greatly appreciated. Edit: One of the six thousand things I've tried. I think this has

How to make sure a file handle has been closed before next operation?

瘦欲@ 提交于 2019-12-23 20:52:51
问题 This is the code I have so far, I wonder if it's correct? $handle = fopen($file, 'w') or die("can't open file"); $closed = fclose($handle); while($closed){ DOAWESOMETHINGS(); // btw I only want to have this run once for each handle $closed = false; } Thank you so much! 回答1: You can check whether the handle has been closed or not using this statement if(!is_resource($handle)){ //Handle closed }else{ //Handle still open } Therefore, if you need to ensure that fclose has worked before running

Basic Java Hangman

一笑奈何 提交于 2019-12-23 20:20:07
问题 Hey guys I am just starting to learn Java as my first programming language! In class we were assigned to make a basic Hangman game with the use of a while and for loops! What I have so far When the user inputs the first guess it does recognize that that characters that he/she guessed was corrected but just continues on and stating that I have guessed an incorrect letter! Help would be very appreciated!! My question is what am I doing wrong in my code? I need the program to tell the user if

expect inside while loop - loops forever

余生颓废 提交于 2019-12-23 20:19:45
问题 I'm new to expect scripts, so please forgive my stumbling... Below is the meat of my expect script. The intent is to scroll thru several screens of output, after each of which the user is prompted with "Continue? [y/n]". Finally, when there are no more screens, a "% " prompt is displayed, which SHOULD cause execution to fall out of the while loop. set more_screens 1 while {$more_screens > 0} { sleep 10 expect { "\[y/n]" { send "y\r"} "% " { set more_screens 0 } } } What happens instead is...