while-loop

getchar() not working in c

那年仲夏 提交于 2019-12-13 07:54:46
问题 getchar() is not working in the below program, can anyone help me to solve this out. I tried scanf() function in place of getchar() then also it is not working. I am not able to figure out the root cause of the issue, can anyone please help me. #include<stdio.h> int main() { int x, n=0, p=0,z=0,i=0; char ch; do { printf("\nEnter a number : "); scanf("%d",&x); if (x<0) n++; else if (x>0) p++; else z++; printf("\nAny more number want to enter : Y , N ? "); ch = getchar(); i++; }while(ch=='y'|

Apply php/MySql while loop in javascript object [closed]

痞子三分冷 提交于 2019-12-13 07:54:39
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I would like to take the following php/mysql loop, and apply the results: $test,$test1,$test2 to the var Data object in the javascript code. This will make the var Data dynamic, pulling its data to construct the

Parents tree in mysql table (while-loop)

萝らか妹 提交于 2019-12-13 07:52:32
问题 Sorry for my English. I have a mysql table like this [ --------------------------] [ parent_id ] [ category_id ] [ --------------------------] Site structured like this: 0 -> 1 -> 2 -> -> 3 -> -> -> 5 -> 4 and table will look like 0 1 0 2 2 3 0 4 3 5 How to write mysql while loop to input 5 and get list of it's parents until 0: 3 2 I know, how to write it in php, but I want to do only 1 query to database, but when I try to run "While" examples from official manuals, it returns a lot of errors

Why does the string inside println method show twice?

試著忘記壹切 提交于 2019-12-13 07:51:01
问题 In the following code why does the string inside println method shows twice.What should I do to show the message once per iteration package practicejava; public class Query { public static void main(String[] args) throws java.io.IOException { System.out.println("Guess a capital letter Character"); while ((char) System.in.read() != 'S') { System.out.println("wrong.guess again to finish the program"); } } } 回答1: When a user writes in console characters, to confirm fact that his input is ready

print the result as soon as user input “done”

梦想与她 提交于 2019-12-13 07:43:18
问题 largest_so_far = None smalest_so_far = None value = float(raw_input(">")) while value != ValueError: value = float(raw_input(">")) if value > largest_so_far: largest_so_far = value elif value == "done": break print largest_so_far I think problem with this is that done is string while input is float type. I have also tried it running using value = raw_input(">") instead of float(raw_input(">") but that prints the result as done 回答1: Few hints: Instead of converting the user input to float

Can't Break Out of While Loop

戏子无情 提交于 2019-12-13 07:37:48
问题 I wrote the following python code. It takes a list of English words I found on the internet and makes them a list so that I can use them for hangman. Well my problem is that every time I run this program and successfully guess the word, it doesn't break out of the while loop. It just keeps going. I can't figure out why for the life of me. Anyone have any clue as to why it isn't printing the final message to the winner? import random words = [] lettersGuessed = [] isGuessed = 0 wordFile = open

Loop to start at a cell and delete the next 600 in the column

感情迁移 提交于 2019-12-13 07:36:59
问题 All of my data is in the "D" column. I want to start a specific cell (ie. D249) and then select the next 600 and delete them (ie. D250-D850). Then I want to skip the next one down (ie. D851) and delete the next 600 below that. I want to do this until it gets to the end, which is like D19000. I think I need to use a while loop to check if data is present in the cell I'm looking at. This is the code I have so far: Sub delete600rows() 'delete600rows Macro 'Keyboard Shortcut: Ctrl+a ActiveSheet

Print new <div> on id iteration change inside php while loop from MySQL result

自作多情 提交于 2019-12-13 07:35:24
问题 I have this MySQL table: +------------+-------------+ | contact_id | _company_id | +------------+-------------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | +------------+-------------+ Im trying to print a new <div> containing all rows with the same _company_id So far I have this code: $previous = ''; while ($result = $stmt->fetch()) { $current = $_company_id; //This should be executed every first iteration and every time $_company_id changes if ($current != $previous) { $html .= '<div

MySQL fetch_assoc() shows 1 less result

◇◆丶佛笑我妖孽 提交于 2019-12-13 07:30:39
问题 i have a table like below: hub dep A B A C B D B E B F E G i use mysql select to get query and my code is like below: $sql = "SELECT dep FROM handd WHERE hub='B'"; $result = $conn->query( $sql ); $row = $result->fetch_assoc(); while($row = $result->fetch_assoc()) { echo "id: " . $row["dep"]."<br>"; } but it just gives me result like below: id: E id: F and i am wondering where is D? 回答1: $row = $result->fetch_assoc(); This line stores the result of 'B D'. It actually should be: $sql = "SELECT

Nested PHP while loop to create a dynamic table that is 2 rows by 5 columns per row

夙愿已清 提交于 2019-12-13 07:09:41
问题 My current code looks like this: <?php $i = 6; //will be pulled from a database if ($i != "10") { $countb = (10-$i); } echo "<table border=\"1\" align=\"left\">"; echo "<tr><th>Results</th>"; echo "</tr>"; while ( $i != 0) { echo "<tr><td>"; echo "Good"; echo "</td>"; $i= $i- 1; } while ( $countb != 0) { echo "<tr><td>"; echo "not good"; echo "</td>"; $countb= $countb- 1; } echo "</table>"; ?> This creates a 1 column 10 row table. I want to have two rows and 5 columns per row. Basically, if